[Resolved] Remove Post Author and Date based on category type

Home Forums Support [Resolved] Remove Post Author and Date based on category type

Home Forums Support Remove Post Author and Date based on category type

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #894924
    Joseph

    I have certain categories that I do not want to show the author and date. I looked at the PHP documentation and found this for the date removal. How or does this also apply to the removal of the author?

    add_filter( ‘generate_post_author_output’, function( $output ) {
    // If we’re on our “my-post-type” post type, remove the author.
    if ( is_post_type_archive( ‘my-post-type’ ) || ‘my-post-type’ == get_post_type() ) {
    return ”;
    }

    // Otherwise, display it.
    return $output;
    } );

    Thank you in advance.

    #895033
    David
    Staff
    Customer Support

    Hi there,

    maybe this article will be helpful:

    https://docs.generatepress.com/article/option_generate_blog_settings/

    #895836
    Joseph

    I crashed the site adding the script to the themes.php. Got it back up. Can you assist with the proper code? The category I am looking to eliminate the author and date is American Heritage Center.
    Thanks David, any help is appreciated.

    #896348
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Try this:

    add_action( 'wp', function() {
        if ( is_category( 'your-category-slug' ) ) {
            add_filter( 'generate_post_date', '__return_false' );
            add_filter( 'generate_post_author', '__return_false' );
        }
    } );

    Just replace your-category-slug with your category.

    #896504
    Joseph

    Hi Tom, added the script and got the message at the very bottom of the attached image I have enclosed. Pretty straight forward but something is not working. I probably missed something.

    Error message

    #896627
    Tom
    Lead Developer
    Lead Developer

    I believe that means WordPress isn’t communicating with the files well enough to update them.

    You could try using a plugin like Code Snippets instead if you can’t access the files via FTP.

    #896719
    epickenyan

    Hi Tom. How about hiding the author byline in a certain category across the site? I have a guest category and I am hiding the byline in single posts using CSS like .category-category name .byline{display: none;}and the above function in code snippets didn’t work.

    Update: Tried this code and it worked. Hope it is a correct code?

    add_action( 'wp', function() {
        if ( has_category( array( 10 ) ) ) {
            add_filter( 'generate_post_author', '__return_false' );
        }
    } );
    #897031
    Tom
    Lead Developer
    Lead Developer

    That’s perfect 🙂

    #897212
    epickenyan

    Thanks…

    #897285
    Joseph

    Epic, thank you much!! That worked perfectly!!

    #897396
    epickenyan

    You are welcome. I justly slightly modified a code shared by Tom in another post.

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