Design System is here - Read the release post

Learn GeneratePress

Developers

Post meta and dates filters

Filters for the post meta shown with each entry — dates, author, categories, tags and comment count — and which post types show it.

Jump to

Dates

generate_post_date

GP Free

The generate_post_date filter allows you to choose whether to display your post dates or not.

Parameters: $value (boolean). Default: true.

add_filter( 'generate_post_date', function( $value ) {
    return $value;
} );

Related: generate_post_date_output Guide: Blog

generate_post_date_output

GP Free

This filter returns the HTML that displays your post date along with your blog posts.

Parameters: $value. Default: shown right, computed at render time:

sprintf(
				$posted_on,
				apply_filters( 'generate_inside_post_meta_item_output', '', 'date' ),
				esc_url( get_permalink() ),
				esc_attr( get_the_time() ),
				$time_string
			)
add_filter( 'generate_post_date_show_updated_only', '__return_true' );
add_filter( 'generate_post_date_output','tu_add_to_post_date' );
function tu_add_to_post_date( $output ) {
    return '<i class="fa fa-clock-o" aria-hidden="true"></i> ' . $output;
}
add_filter( 'generate_post_date_output', function( $output, $time_string ) {
	printf( '<span class="posted-on">%s</span> ',
		$time_string
	);
}, 10, 2 );

Related: generate_post_date Guide: Blog

generate_post_date_show_updated_only

GP Free

By default, the HTML for the published date and updated date (if it exists) is added to your site.

Parameters: $value. Default: false.

add_filter( 'generate_post_date_show_updated_only', '__return_true' );

Guide: Blog

Back to top

Author

generate_post_author

GP Free

The generate_post_author filter allows you to choose whether to display your author link or not.

Parameters: $value (boolean). Default: true.

add_filter( 'generate_post_author', function( $value ) {
    return $value;
} );

Related: generate_post_author_output Guide: Blog

generate_post_author_output

GP Free

This filter returns the HTML that displays your post author along with your blog posts.

Parameters: $value. Default: shown right, computed at render time:

sprintf(
				$byline,
				apply_filters( 'generate_inside_post_meta_item_output', '', 'author' ),
				esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
				/* translators: 1: Author name */
				esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
				esc_html( get_the_author() ),
				generate_get_microdata( 'post-author' ),
				'microdata' === $schema_type ? ' itemprop="url"' : '',
				'microdata' === $schema_type ? ' itemprop="name"' : '',
				generate_is_using_hatom() ? ' vcard' : ''
			)
add_filter( 'generate_post_author_output', function( $output ) {  
    return '<i class="fa fa-user-circle" aria-hidden="true"></i> ' . $output; 
} );
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;
} );
add_filter( 'generate_post_author_output', function( $output ) {    
    return '<a href="MY CUSTOM URL">My Name</a>';
} );
add_filter( 'generate_post_author_output', function() {
    printf( ' <span class="byline">%1$s</span>',
        sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%1$s <span class="fn n author-name" itemprop="name">%4$s</span></span>',
            __( 'by','generatepress'),
            esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
            esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ),
            get_the_author() ) ),
            esc_html( get_the_author() )
        ) 
    );
} );

Related: generate_post_author Guide: Blog

Back to top

Categories, tags and terms

generate_show_categories

GP Free

The generate_show_categories filter allows you to choose whether to display your category links or not.

Parameters: $value (boolean). Default: true.

add_filter( 'generate_show_categories', function( $value ) {
    return $value;
} );

Guide: Blog

generate_category_list_output

GP Free

The generate_category_list_output filter controls the output of your categories as shown in your post meta along with your blog posts.

Parameters: $value. Default: shown right, computed at render time:

sprintf(
					'<span class="cat-links">%3$s<span class="screen-reader-text">%1$s </span>%2$s</span> ',
					esc_html_x( 'Categories', 'Used before category names.', 'generatepress' ),
					$categories_list,
					apply_filters( 'generate_inside_post_meta_item_output', '', 'categories' )
				)
add_filter( 'generate_category_list_output', function() {
    $categories = apply_filters( 'generate_show_categories', true );

    $term_separator = apply_filters( 'generate_term_separator', _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ), 'categories' );
    $categories_list = get_the_category_list( $term_separator );

    return sprintf( '<span class="cat-links">%3$s<span class="screen-reader-text">%1$s </span>%2$s</span> ', // WPCS: XSS ok, sanitization ok.
        esc_html_x( 'Categories', 'Used before category names.', 'generatepress' ),
        strip_tags( $categories_list ),
        apply_filters( 'generate_inside_post_meta_item_output', '', 'categories' )
    );
} );

Guide: Blog

generate_show_tags

GP Free

The generate_show_tags filter allows you to choose whether to display your tag links or not.

Parameters: $value (boolean). Default: true.

add_filter( 'generate_show_tags', function( $value ) {
    return $value;
} );

Guide: Blog

generate_tag_list_output

GP Free

The generate_tag_list_output filter controls the output of your tags as shown in your post meta along with your blog posts.

Parameters: $value. Default: shown right, computed at render time:

sprintf(
					'<span class="tags-links">%3$s<span class="screen-reader-text">%1$s </span>%2$s</span> ',
					esc_html_x( 'Tags', 'Used before tag names.', 'generatepress' ),
					$tags_list,
					apply_filters( 'generate_inside_post_meta_item_output', '', 'tags' )
				)
add_filter( 'generate_tag_list_output', function( $value ) {
    return $value;
} );

Guide: Blog

generate_term_separator

GP Free

The generate_term_separator filter allows change the default comma between each meta terms.

Parameters: $value. Default: _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ).

add_filter( 'generate_term_separator', function() {
    return '-';
} );

Guide: Blog

Back to top

generate_show_comments

GP Free

The generate_show_comments filter allows you to choose whether to display the amount of comments/link to your comments section in each post.

Parameters: $value (boolean). Default: true.

add_filter( 'generate_show_comments', function( $value ) {
    return $value;
} );

Guide: Blog

Back to top

Which meta appears

generate_entry_meta_post_types

GP Free

This filter allows you to tell the entry meta to display on your custom post types.

Parameters: $value. Default: shown right, computed at render time:

array(
			'post',
		)
add_filter( 'generate_entry_meta_post_types', function( $types ) {
    $types[] = 'my-post-type';
    $types[] = 'recipes';

    return $types;
} );

Guide: Blog

generate_footer_meta_post_types

GP Free

This filter allows you to tell the footer entry meta to display on your custom post types.

Parameters: $value. Default: shown right, computed at render time:

array(
			'post',
		)
add_filter( 'generate_footer_meta_post_types', function( $types ) {
    $types[] = 'my-post-type';
    $types[] = 'recipes';

    return $types;
} );

Guide: Blog

generate_header_entry_meta_items

GP Free

The generate_header_entry_meta_items allows us to re-order or add entry meta items.

Parameters: $value. Default: shown right, computed at render time:

array(
			'date',
			'author',
		)
add_action( 'generate_post_meta_items', function( $item ) {
    if ( 'my-meta-item' === $item ) {
        echo 'My custom meta item';
    }
} );
add_filter( 'generate_header_entry_meta_items', function() {
    return array(
        'date',
        'author',
        'categories',
    );
} );
add_filter( 'generate_header_entry_meta_items', function() {
    $items[] = 'custom-meta-item';

    return $items;
} );
add_filter( 'generate_header_entry_meta_items', function( $items ) {
    return array_diff( $items, array( 'author' ) );
} );

Guide: Blog

generate_footer_entry_meta_items

GP Free

The generate_footer_entry_meta_items allows us to re-order or add footer meta items.

Parameters: $value. Default: shown right, computed at render time:

array(
			'categories',
			'tags',
			'comments-link',
			'post-navigation',
		)
add_filter( 'generate_footer_entry_meta_items', function() {
    return array(
        'date',
        'categories',
        'comments-link',
        'post-navigation',
    );
} );

Guide: Blog

generate_inside_post_meta_item_output

GP Free

The generate_inside_post_meta_item_output filter allows you to add content after the post meta.

Parameters: $value. Default: '' (empty string).

add_filter( 'generate_inside_post_meta_item_output', function( $output, $item ) {
	if ( 'categories' === $item ) {
        return ' Published in ';
    }
    return $output;
}, 50, 2 );

Guide: Blog

Back to top