Site logo

Archived topic

Customizing content-single PHP file

8 replies · Started by Andreas on April 17, 2019

Viewing posts 1–9 of 9

I am trying to customize the custom-single.php file (thumbnail) but I am not sure how to access the code for the thumbnail directly.

I only see:

		<?php
		/**
		 * generate_before_content hook.
		 *
		 * @since 0.1
		 *
		 * @hooked generate_featured_page_header_inside_single - 10
		 */
		do_action( 'generate_before_content' );
		?>

Could you let me know how I can customize the raw code and also what if I like to have the featured image somewhere else on the page. What would be the best approach here be?

Thanks in advance.

Hi there,

The featured image is hooked into the template. Where are you wanting it to be instead?

Hi Tom,

thank you very much for your feedback. Yes, I saw the various hooks in the content-single.php template and also the drop-down placement options in the Customizer.

Let's say I wanted to add code that would show multiple thumbnails in a slider or slightly change the php code for the display of the thumbnails.

Is there any place/file where I could overwrite the current raw thumbnail placement php code non-destructively -- meaning it would not be overwritten in a generatepress theme update or what would you suggest would be the best approach for such a case?

Thanks in advance for your help!

You can unhook the current featured image:

remove_action( 'generate_before_content', 'generate_featured_page_header_inside_single', 10 );

Then you can add your own:

add_action( 'generate_before_content', function() {
    if ( is_single() ) {
        the_post_thumbnail(); // Or whatever you need to do.
    }
} );

Hi Tom,

thanks for the helpful and knowledgeable answer - would I add these code snippets in the content-single.php file or the global functions.php file?

Thanks agin and I am looking forward to trying this out!

Hi Tom,

I tested your code snippets putting them in the functions.php file of the child theme and the add_action works but the remove_action does not work.

The customizer has the featured image for 'Post' set to 'Below Title' so I changed your remove code to:

remove_action( 'generate_after_entry_title', 'generate_featured_page_header_inside_single', 10 );

and:

remove_action( 'generate_after_entry_header', 'generate_featured_page_header_inside_single', 10 );

and also:

remove_action( 'generate_before_content', 'generate_featured_page_header_inside_single', 10 );

but neither of these were able to remove the Featured Image on the Single Post page.

If you could double-check what the issue might be that would be great.

Thank you!

Try this instead:

add_action( 'wp', function() {
    remove_action( 'generate_after_entry_header', 'generate_blog_single_featured_image' );
}, 100 );

Hi Tom,
yes, this one worked like a charm - thanks so much.

You're welcome :)

This archived topic is closed to new replies.