• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

How to display author name only on posts from specific categories

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › How to display author name only on posts from specific categories

This topic is: resolved

Tagged: .post-info, entry-meta, Magazine Pro

  • This topic has 18 replies, 2 voices, and was last updated 7 years, 11 months ago by swann83.
Viewing 19 posts - 1 through 19 (of 19 total)
  • Author
    Posts
  • September 4, 2018 at 11:11 am #222927
    swann83
    Member

    Hi,

    I'm using Magazine Pro theme. I've customized the post info so I have [post_date], [post_comments] and [post_edit] in all categories and posts. Now I'm looking for a way to also display [post_author] in all posts from specific categories. And I want it to be displayed just in the default output of single posts – like this: [post_author], [post_date], [post_comments] and [post_edit] –, not in the homepage.

    Thanks,

    Swann

    September 4, 2018 at 11:23 am #222928
    Brad Dalton
    Participant

    Try this https://my.studiopress.com/documentation/snippets/entry-header-html5/customize-the-entry-header/

    You can use conditional tags to control which pages the code executes.


    Tutorials for StudioPress Themes.

    September 4, 2018 at 12:15 pm #222929
    swann83
    Member

    Yes, thank you.

    This is exactly my customization in my theme’s functions.php file:

    add_filter( 'genesis_post_info', 'post_info_filter' );
    function post_info_filter($post_info) {
    $post_info = '[post_date] [post_comments] [post_edit]';
    return $post_info;
    }

    I've tried to add this ("f1" is the category whose posts I want the author name to be displayed in) but it doesn't work:

    add_filter( 'genesis_post_info', 'post_info_filter' );
    if ( is_category('f1') ) {
    $post_info = '[post_author] [post_date] [post_comments] [post_edit]';
    return $post_info;
    }

    I'm not sure I'm good enough to use conditional tags but anyway I don't know if it could work for my purpose (I want author name not to be displayed in the homepage, above excerpts, but just in the single post).

    Thanks.

    September 5, 2018 at 2:57 am #222936
    Brad Dalton
    Participant

    Try in_category which is different to is_category

    https://codex.wordpress.org/Conditional_Tags#A_Category_Page


    Tutorials for StudioPress Themes.

    September 5, 2018 at 7:00 am #222943
    swann83
    Member

    Unfortunately, it doesn't work:

    add_filter( 'genesis_post_info', 'post_info_filter' );
    if ( in_category('f1') ) {
    $post_info = '[post_author] [post_date] [post_comments] [post_edit]';
    return $post_info;
    }

    Any idea what I'm doing wrong here?

    Thanks.

    September 5, 2018 at 7:50 am #222945
    Brad Dalton
    Participant

    That should add the author on posts in category f1.

    However, it may not work if you have a plugin active which uses the same hook ( Like Genesis Simple Edits ) or other conflicting code.


    Tutorials for StudioPress Themes.

    September 5, 2018 at 7:57 am #222946
    swann83
    Member

    I have Simple Hooks, that is very important for my site. Is it creating conflicts? How can I solve them?

    September 5, 2018 at 11:22 am #222958
    Brad Dalton
    Participant

    Based on my testing, this code works:

    add_filter( 'genesis_post_info', 'post_info_filter' );
    function post_info_filter( $post_info ) {
    if ( in_category('f1') ) {
    $post_info = '[post_author]';
    return $post_info;
        }
    }
    

    Tutorials for StudioPress Themes.

    September 6, 2018 at 3:05 am #222994
    swann83
    Member

    Ok, it works only if I declare it once. If I use both of these codes then an error occurs: Cannot redeclare post_info_filter() (previously declared in....

    add_filter( 'genesis_post_info', 'post_info_filter' );
    function post_info_filter($post_info) {
    $post_info = '[post_date] [post_comments] [post_edit]';
    return $post_info;
    }

    add_filter( 'genesis_post_info', 'post_info_filter' );
    function post_info_filter($post_info) {

    if ( in_category('f1') ) {
    $post_info = '[post_author] [post_date] [post_comments] [post_edit]';
    return $post_info;
    }

    }

    As I said I need [post_date] + [post_comments] + [post_edit] to be displayed in all categories and posts, by default, and also [post_author] in all posts from only two categories (F1 and News). And by the way, I need that info (post author) to be displayed just in the default output of single posts, not visible below the excerpts in the homepage.

    Thanks,

    Swann

    September 6, 2018 at 3:53 am #222998
    Brad Dalton
    Participant

    You can use a else if statement.

    Example :

    if (condition) {
        code to be executed if condition is true;
    } else {
        code to be executed if condition is false;
    }
    

    Or like this :

    if (condition) {
        code to be executed if this condition is true;
    } elseif (condition) {
        code to be executed if this condition is true;
    } else {
        code to be executed if all conditions are false;
    }
    

    Or a ternary operator examples


    Tutorials for StudioPress Themes.

    September 6, 2018 at 5:03 am #223002
    swann83
    Member

    Great! It works.

    What can I do to keep only author name from being displayed in excerpts in the homepage? I want to display it just in the single post view.

    Thanks,

    Swann

    September 6, 2018 at 5:12 am #223004
    Brad Dalton
    Participant

    Link to your site please.


    Tutorials for StudioPress Themes.

    September 6, 2018 at 6:08 am #223006
    swann83
    Member

    Homepage

    September 6, 2018 at 6:11 am #223007
    Brad Dalton
    Participant

    Use this 2nd method https://www.studiopress.community/topic/how-to-display-author-name-only-on-posts-from-specific-categories/#post-222998


    Tutorials for StudioPress Themes.

    September 6, 2018 at 6:24 am #223008
    swann83
    Member

    Sorry, how do I do that? The first method seems to be fine.

    add_filter( 'genesis_post_info', 'post_info_filter' );
    function post_info_filter($post_info) {
    
    if ( in_category( array( 10,2640,4678,7084 ) )  ) {
    $post_info = 'di <em>[post_author]</em> <br/> [post_date] [post_comments] [post_edit]';
    return $post_info;
    } else {
    $post_info = '[post_date] [post_comments] [post_edit]';
    return $post_info;
    }
    
    }

    I just want the author name not to be visible in the homepage.

    Thanks.

    September 6, 2018 at 8:30 am #223011
    Brad Dalton
    Participant

    I wrote this for you https://wpsites.net/web-design/conditional-post-info/

    You should be at a stage where you can work out the conditionals and use the following method :

    if (condition) {
        code to be executed if this condition is true;
    } elseif (condition) {
        code to be executed if this condition is true;
    } else {
        code to be executed if all conditions are false;
    }
    

    Some work on this is required at your end.


    Tutorials for StudioPress Themes.

    September 6, 2018 at 10:18 am #223016
    swann83
    Member

    Thank you, braddalton. I appreciate it.

    I'm sorry my English isn't good enough. I haven't been able to make it quite clear that I have very limited technical knowledge. I'm fairly satisfied with the current configuration, but it would be best if I could display the entry meta with authors name on single posts only (from those categories) and the standard entry meta without authors name (only date, comments and edit) in the entry header, including front and blog pages.

    Thanks,

    Swann

    September 6, 2018 at 10:59 am #223019
    Brad Dalton
    Participant

    See here https://www.studiopress.community/topic/how-to-display-author-name-only-on-posts-from-specific-categories/#post-223011


    Tutorials for StudioPress Themes.

    September 6, 2018 at 12:28 pm #223021
    swann83
    Member

    Ok, I wrote this and it works.

    add_filter( 'genesis_post_info', 'post_info_filter' );
    function post_info_filter($post_info) {
    if ( in_category( array( 10,2640,4678,7084 ) ) AND ( is_single() ) ) {
    $post_info = 'di <em>[post_author]</em> <br/> [post_date] [post_comments] [post_edit]';
    } else {
    $post_info = '[post_date] [post_comments] [post_edit]';
    }
    return $post_info;
    }

    Thank you so much for your time, braddalton.

    Swann.

  • Author
    Posts
Viewing 19 posts - 1 through 19 (of 19 total)
  • The topic ‘How to display author name only on posts from specific categories’ is closed to new replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble