Site logo

Archived topic

How can I put a standard text below the featured image of SOME blog posts?

5 replies · Started by crosby87 on May 9, 2021

Viewing posts 1–6 of 6

Hi there,

There are multiple ways of adding this in.

One is by changing the actual content template of using Block Elements. You can add your disclaimer when you change the template.

Another is by hooking your disclaimer after the featured image.

Example: Add disclaimer to post ID 1 and 2.

add_action( 'generate_after_entry_header', function(){
	if(is_single( array( '1','2' ) ) && has_post_thumbnail()){
		$disclaimer_message = 'This is a sample disclaimer';
		echo '<figcaption class="featured-image-caption">'.$disclaimer_message .'</figcaption>';
	}
},20);

You can also try creating a custom featured-image.php on your child theme for this.

Hi Elvin,

I have used the second option as thats what I would need, however, it does not work.

The code you provided simply appears on the post to which I applied the hook too: https://imgur.com/GKQcp4p

This is how the hook looks like inside Elements: https://imgur.com/czXX6xW

Could you please help? Thanks.

Hi there,

that function Elvin provided cannot be added to a Hook Element.
It would either need to go in your child themes functions.php or added using the Code Snippets plugin.

Or to use the Hook Element you would only add this:

if(is_single( array( '1','2' ) ) && has_post_thumbnail()){
    $disclaimer_message = 'This is a sample disclaimer';
    echo '<figcaption class="featured-image-caption">'.$disclaimer_message .'</figcaption>';
}

However, that would require you to change the array values to match the IDs of each of the posts you want it displayed on...

So lets take a step back - how will you determine which posts you want the disclaimer on ? Do the posts have a specific taxonomy ( eg. category , tag ) term?

Hi David,

Thanks for the answer.

It will be mostly random - its not like they would all fall into a specific category or tag.

I would choose the page that I want to apply it to in the display rules in Elements.

Not sure if you have seen the link above, but I would like something like this: https://imgur.com/VaXbLFS

I would do this - first read this topic:

https://generatepress.com/forums/topic/header-layout-control-for-client/#post-1421567

With that in place, create a new Element Display Term eg. disclaimer

Then create a Block Element, add your disclaimer content, set the Hook to generate_after_entry_header.
And then set the Display Rules to match Post Element Controls > Term.

Then whenever you want the disclaimer added you just need to add the term to the post.

This archived topic is closed to new replies.