Site logo

[Resolved] PHP Function to remove entry header

Home Forums Support [Resolved] PHP Function to remove entry header

Home Forums Support PHP Function to remove entry header

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #1323849
    Fabien

    Hi,

    Is there a php function to remove the entry-header within a post ?

    Thanks !

    #1323870
    Leo
    Staff
    Customer Support

    Hi there,

    So you want to remove the post title and entry meta?

    Would this for both the posts page and single post?

    #1324647
    Fabien

    Yes, I want to remove the div.entry-header (and it’s content : title, featured image, meta) using a PHP function. I will target specific post type.

    Thanks

    #1324986
    David
    Staff
    Customer Support

    Hi there,

    there isn’t a hook for removing the entry-header container.
    To do that you would need to create a custom template of the content-single and remove that HTML element:

    https://github.com/tomusborne/generatepress/blob/master/content-single.php

    #1325216
    Fabien

    Thanks David ! I think having function would be nice 😉 Could that be added in the roadmap ?

    #1325226
    David
    Staff
    Customer Support

    As the entry-header is a core element of the single post – removing it feels like a custom template is required. But i will mention it to Tom 🙂

    #1325283
    Fabien

    Yes it would make sense instead of having empty html tags : https://share.getcloudapp.com/GGuoAKzo

    #1589866
    Fabien

    Hi @Tom,

    Any updates on this ? It would make sense to be able to remove it with a function.

    Thanks

    #1591060
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Yes, this filter was added in 3.0: https://github.com/tomusborne/generatepress/blob/3.0.2/inc/theme-functions.php#L148

    So you can do this:

    add_filter( 'generate_show_entry_header', function( $show ) {
        if ( $my_condition ) {
            $show = false;
        }
    
        return $show;
    } );
    #1591634
    Fabien

    Awesome Tom !

    #1592397
    Tom
    Lead Developer
    Lead Developer

    Glad I could help 🙂

    #1675792
    Edmund

    Hi, I am looking to remove the entry header from the published post.
    I am new to GeneratePress, so apologies for my ignorance.
    I see that a “filter” shown above was added in 3.0 – but what do you need to do to use it.
    I tried pasting the “so you can do this” code in my child theme Functions.php file, but that did not work, so I tried pasting it in the custom CSS but again that did not work.
    Please advise.
    Thanks

    #1676334
    Ying
    Staff
    Customer Support

    Hi Edmund,

    This is how you add PHP 🙂
    Adding PHP: https://docs.generatepress.com/article/adding-php/

    #1676470
    Edmund

    Hi Ying,
    Thank you for your reply. I did try pasting into Functions.php of my child theme, but it did not work.
    However I have since found the solution on each “Page” in WordPress, in the toolbar on the right, has at the bottom, “disable elements” one of which is the content Title.
    So that worked for me.

    #1676484
    Leo
    Staff
    Customer Support

    You can try creating a layout element if you need to do that globally:
    https://docs.generatepress.com/article/layout-element-overview/#disable-element

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