Black Friday Sale! Get up to $30 off GP Premium! Learn more ➝

Reply To: Caption for post thumbnails

Home Forums Support Caption for post thumbnails Reply To: Caption for post thumbnails

Home Forums Support Caption for post thumbnails Reply To: Caption for post thumbnails

Emily Condit


Okay, so what I wanted to do was to insert the image with the copyright AFTER the entry header on my main page where masonry is enabled and BEFORE the entry header on the single post page for the linked post.

I looked at the notes in your code and you had a conditional that said if(!is_singular() && !is_404()) which means the code would only apply to posts that are either in masonry blocks or on a page where multiple posts are listed one after the other.

The plugin you talked about takes care of that issue without any additional code (as far as I can tell anyway. I have masonry enabled and the copyrights appeared under the featured thumbnails without any additional code). The thing the plugin DOESN’T do, at least in conjunction with this theme, is to add the copyright under featured images on single posts.

I’m not sure HOW to remove the featured images on single posts. The code you gave doesn’t remove them. If you know how to remove the featured image on a single post, I can change the code in my functions.php so I don’t need extra CSS to hide it.

So the full fix for what I needed to do is to download the plugin you mentioned which took care of the copyright on the thumbnails, modify your code so that it only operated on single posts using the before_content hook instead of the after_entry_header hook, and adjust the CSS to hide the featured image and remove the margin from the top of the single post image so that it was flush with the top widget of my sidebar.

Here’s the plugin link you gave us (posting for those who might want the full fix in one topic post):

***This is an aside from the full fix***
This plugin either has some errors or doesn’t work the way it’s supposed to with your theme. In the PHP code, the div for the caption APPEARS to be built correctly but when in use, does not actually display the way it’s built. But fortunately, this only really matters if you want to modify the CSS of the caption text separately from the source. There is a workaround, however. These rules will allow you to modify the caption text separately from the caption source:

.cc-featured-image-caption-text, .cc-featured-image-caption-text a {
/*put all rules for the caption SOURCE here*/

.cc-featured-image-caption {
/*put all rules for the caption TEXT here*/
***end aside. resume full fix***

Next, I modified Tom’s code as follows. This is my full functions.php file in the blank child theme for Generate Press:

 * Generate child theme functions and definitions
 * @package Generate

function generate_remove_blog_post_image()

      //this is removing the generate_before_content because on a single post, I want my image to appear BEFORE the entry header. This code does not remove a single post featured image. Tom, if you know how to remove a single post image, please, let me know the code.

      remove_action( 'generate_before_content', 'generate_blog_post_image' );

//this adds the image with the post with its caption before the entry header

add_action( 'generate_before_content', 'generate_post_image_caption' );
function generate_post_image_caption()
	// If there's no featured image, return
	if ( ! has_post_thumbnail() )
	//Modified. This is checking for a post that IS a single post and NOT a 404
	if ( is_singular() && ! is_404()) {
		<div class="post-image">
			<a href="<?php the_permalink();?>" title="<?php the_title(); ?>"><?php the_post_thumbnail( 'full', array('itemprop' => 'image') ); ?><?php if ( function_exists( 'cc_featured_image_caption' ) ) : cc_featured_image_caption(); endif; ?></a>

Finally, this added to the custom style sheet of the theme (I’m using Jetpack per Tom’s suggestion) will remove the featured image from a single post:

.inside-article .page-header-image-single {
display: none;

This CSS pulls the single post image up so it’s flush with the top of the widget sidebar(s) and gives some breathing room between the caption and the entry header:

.inside-article .post-image {
margin-bottom: 20px;
margin-top: 0;

I hope that will be helpful to someone. I would still like to know the php code to remove a single post featured image though.

Thanks, Tom.

You rock.

🙂 Emily