Site logo

[Resolved] Remove Date/updated date from a specific category posts

Home Forums Support [Resolved] Remove Date/updated date from a specific category posts

Home Forums Support Remove Date/updated date from a specific category posts

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #2271533
    Rohan Verma

    Hello,
    I want to remove the date (Meta) from all the posts from a specific category. I have shared the link to the category. I am now showing the updated date on all the posts across the site. But now I want to hide the date meta from a specific category article. Please help

    Thanks and Regards

    #2271645
    David
    Staff
    Customer Support

    Hi there,

    try this:

    add_filter( 'generate_header_entry_meta_items', function( $items ) {
    
        if ( is_category( 'your-category' ) || in_category( 'your-category' ) ) {
            return array_diff( $items, array( 'date' ) );
        }
        
    } );

    More info on that filter here:

    https://docs.generatepress.com/article/generate_header_entry_meta_items/#removing-an-item

    #2272314
    Rohan Verma

    It is removing meta from the whole site.

    #2272337
    Fernando
    Customer Support

    Hi Rohan,

    To clarify, are you wanting to remove the date meta only on single posts pages?

    If so, kindly modify the code into something like this:

    add_filter( 'generate_header_entry_meta_items', function( $items ) {
    
        if ( is_single() &&  in_category( 'your-category’ ) ) {
            return array_diff( $items, array( 'date' ) );
        }
    	return $items;
        
    } );

    Kindly replace your-category with your category slug.

    Kindly let us know how it goes.

    #2272338
    Rohan Verma

    No from all the posts (articles) from a specific category. Shared the link of the category in private.

    #2272341
    Fernando
    Customer Support

    So just in category pages? If so, use this instead:

    add_filter( 'generate_header_entry_meta_items', function( $items ) {
    
        if ( is_category( 'your-category' ) ) {
            return array_diff( $items, array( 'date' ) );
        }
    	return $items;
        
    } );
    #2272357
    Rohan Verma

    It giving error: https://ibb.co/pxkWxQ9

    #2272359
    Fernando
    Customer Support

    I see. Can you try the code above again? I modified it.

    #2272363
    Rohan Verma

    As we are showing a modified date so the above php is not working. Its removing dates from the archive but inside article dates are still showing

    #2272367
    Fernando
    Customer Support

    To clarify, what specific date are you trying to remove? Can you provide a screenshot of it?

    Kindly let us know.

    #2272531
    Rohan Verma

    Here is a screenshot: https://pasteboard.co/9ZuZERnn3jJg.jpg. We want to remove the date from all the articles of a specific category.

    #2272600
    David
    Staff
    Customer Support

    What other functions relating to the post meta are you using on the site ?

    #2273424
    Rohan Verma

    Showing updated date instaed of publish date with this php

    add_filter( ‘generate_post_date_output’, function( $output, $time_string ) {
    $time_string = ‘<time class=”entry-date published” datetime=”%1$s” itemprop=”datePublished”> %2$s</time>’;

    if ( get_the_date() !== get_the_modified_date() ) {
    $time_string = ‘<time class=”entry-date updated-date” datetime=”%3$s” itemprop=”dateModified”> %4$s</time>’;
    }

    $time_string = sprintf( $time_string,
    esc_attr( get_the_date( ‘c’ ) ),
    esc_html( get_the_date() ),
    esc_attr( get_the_modified_date( ‘c’ ) ),
    esc_html( get_the_modified_date() )
    );

    return sprintf( ‘<span class=”posted-on”>%s</span> ‘,
    $time_string
    );
    }, 10, 2 );

    #2273437
    Fernando
    Customer Support

    Yes, this code should work if you’re removing the date from single posts/articles of a specific category:

    add_filter( 'generate_header_entry_meta_items', function( $items ) {
    
        if ( is_single() && in_category( 'affiliate-marketing' ) ) {
            return array_diff( $items, array( 'date' ) );
        }
    	return $items;
        
    } );

    Hope this clarifies!

    #2273441
    Rohan Verma

    Great, it’s working. Just one last thing. The data is removed from all the articles from that category that we wanted. But in the archive, it is still showing the date. Shared the link on private chat.

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