[Resolved] Customizing content-single PHP file

Home Forums Support [Resolved] Customizing content-single PHP file

Home Forums Support Customizing content-single PHP file

  • This topic has 8 replies, 2 voices, and was last updated 5 years ago by Tom.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #872012
    Andreas

    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.

    #872057
    Tom
    Lead Developer
    Lead Developer

    Hi there,

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

    #872149
    Andreas

    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!

    #872767
    Tom
    Lead Developer
    Lead Developer

    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.
        }
    } );
    #872845
    Andreas

    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!

    #872948
    Andreas

    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!

    #873050
    Tom
    Lead Developer
    Lead Developer

    Try this instead:

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

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

    #873611
    Tom
    Lead Developer
    Lead Developer

    You’re welcome 🙂

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.