GeneratePress: Show Category Below Title

GeneratePress, by default, shows the Category below the post content. This is not ideal for most blogs. But there is a way to show the Category below the Title, like this:

Code to Show Category Below Title in GeneratePress

add_action( 'generate_after_entry_title', 'lh_add_cat_below_title' );
function lh_add_cat_below_title() {
    if (is_single() ) {
        $categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ) );
        $categories_list = sprintf( '<span class="cat-links-below-title"><span class="screen-reader-text">%1$s </span>%2$s</span> | ',
            _x( 'Categories', 'Used before category names.', 'generatepress' ),
            $categories_list
        );
    }

    ?>
    <div class="entry-meta-cat">
	<?php echo $categories_list; ?>
    </div>
    <?php
}
PHP

How to add this code to your WordPress site

Leave a Comment