简体   繁体   中英

Populate title attribute of background-image using php

I want to credit the author of a few the photos on my website in the title tag. I just added the fields in the admin sections using the instructions given here and this works fine.

Now i want to display that information in the title tag of a photo but that photo is set as a background image and therefor im not able to add a title tag to it and thus the info isnt showing. It is said as a background-image because it sometimes has an extra layer (partially) on top of it.

<figure 
    style="<?php echo "background-image:url('".$snakeImageUrl."'); background-size:cover;"; ?>" 
    title="<?php echo get_post_meta($post->ID, 'be_photographer_name', true); ?> 
    <?php echo get_post_meta($post->ID, 'be_photographer_url', true); ?>">
</figure>

How am i still be able to achieve this result?

I think you're going to have trouble here, I don't know of properties being able to be attached to content that's delivered via CSS which is what the style attribute within with figure selector is.

Can you edit the template? If so, why not have the image as a HTML image element and then use CSS and position:absolute on the content that you want placed over the background image?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM