Exclude Category Links From Genesis Post Categories Shortcode

The genesis post categories shortcode prints all the categories you have assigned to each post in the entry footer on single posts and archives. The function for this is located in genesis > lib > shortcodes > post.php.

add_shortcode( 'post_categories', 'genesis_post_categories_shortcode' );

function genesis_post_categories_shortcode( $atts ) {

<pre><code>$defaults = array(
    'sep'    =&gt; ', ',
    'before' =&gt; __( 'Filed Under: ', 'genesis' ),
    'after'  =&gt; '',
);

$atts = shortcode_atts( $defaults, $atts, 'post_categories' );

$cats = get_the_category_list( trim( $atts['sep'] ) . ' ' );

//* Do nothing if no cats
if ( ! $cats ) {
    return '';
}

if ( genesis_html5() )
    $output = sprintf( '&lt;span %s&gt;', genesis_attr( 'entry-categories' ) ) . $atts['before'] . $cats . $atts['after'] . '&lt;/span&gt;';
else
    $output = '&lt;span class="categories"&gt;' . $atts['before'] . $cats . $atts['after'] . '&lt;/span&gt;';

return apply_filters( 'genesis_post_categories_shortcode', $output, $atts );
</code></pre>

}

The function for the shortcode uses get_the_category_list which is located in wordpress > wp-includes > category-template.php.

function get_the_category_list( $separator = '', $parents='', $post_id = false ) {

Demo Video

Here’s a demonstration showing you how the code removes 2 category links from the entry meta in the entry footer of the Genesis Sample child theme by StudioPress:

Here’s the code for logged in members:

You can also use the code in this download folder to exclude categories by category ID.

Download Folder

Related Tutorials


Comments

4 responses to “Exclude Category Links From Genesis Post Categories Shortcode”

  1. Marcelo Campiglia Avatar
    Marcelo Campiglia

    Hello,

    In the second option, how can I exclude multiple categories?

    Thanks,

    Marcelo

    1. Why can’t you use the first function for this?

      1. Marcelo Campiglia Avatar
        Marcelo Campiglia

        Hello,

        Thank you very much for your super fast answer. This code is great, it is very simple and clean, and it does exactly what I want. It is a very elegant solution, love it!

        Thank you 🙂

        Marcelo

Leave a Reply

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.