• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP SITES

2665

Original Genesis Tutorials & 5000+ Guaranteed Code

Snippets

  • Support
  • Newsletter
  • Videos
  • Log in

Premium Member? - Request custom code

Conditional Genesis Post Info

This tutorial provides 2 different ways to modify what entry meta is displayed in the post info.

If you want to modify the post info conditionally, you can use a :

  1. if…else statement or
  2. a ternary operator.

if…else statement #

These code snippets will display the post author along with the other standard entry meta when the post is in category news.

If not in category news, the post author is removed and only the date, comments and edit link are displayed.

Add 1 of the following code snippets only to your child themes functions file.

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

if ( in_category('news') ) {

$post_info = '[post_author] [post_date] [post_comments] [post_edit]';

} else {

$post_info = '[post_date] [post_comments] [post_edit]';

    }
    
return $post_info;
    
}

You can also write the code like this :

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

if ( in_category('news') ) :

$post_info = '[post_author] [post_date] [post_comments] [post_edit]';

else :

$post_info = '[post_date] [post_comments] [post_edit]';

endif;
    
return $post_info;
    
}

Learn more about using if else and if elseif else conditional statements.

ternary operator #

You can also use a ternary operator with conditional tag and write the filter function like this :

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

$post_info = in_category('news') ? '[post_author] [post_date] [post_comments] [post_edit]' : '[post_date] [post_comments] [post_edit]';

return $post_info;
    
}

Here’s another way to write the code using variables :

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

$include_author = '[post_author] [post_date] [post_comments] [post_edit]';

$remove_author = '[post_date] [post_comments] [post_edit]';

$post_info = in_category('news') ? $include_author : $remove_author;

return $post_info;
    
}

Entry Meta

Reader Interactions

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

PHP Code

template_include

get_body_class

if else

array

class_exists

foreach

sprintf

add_action

printf

variable

Advertise · WPEngine · Genesis · Log in

  • How Premium Membership Works
  • Sign Up
  • Support
  • Subscription Details/Invoice
  • Tagged Tutorials
  • Access-Download Problems