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

WP SITES

2785

Original Genesis & WooCommerce Tutorials & 6000+ Guaranteed Code

Snippets

  • Try Premium
  • Log in

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:

Register for full access

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

Download Folder

Related Tutorials

  • Exclude Child Category Links From Entry Meta
  • Modify Genesis Post Categories Shortcode

Entry Meta Post Categories

Reader Interactions

Comments

  1. Marcelo Campiglia says

    October 17, 2020 at 9:49 pm

    Hello,

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

    Thanks,

    Marcelo

    Log in to Reply
    • Brad Dalton says

      October 18, 2020 at 6:14 am

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

      Log in to Reply
    • Brad Dalton says

      October 18, 2020 at 6:34 am

      Try this code using category ID’s https://wpsites.net/download/97139

      Log in to Reply
      • Marcelo Campiglia says

        October 18, 2020 at 12:42 pm

        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

        Log in to Reply

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

Code written by Brad Dalton specialist for Genesis, WooCommerce & WordPress theme customization. Read More…

Advertise · WPEngine · Genesis · Log in

  • Access Problems
  • Account Details
  • Consulting
  • Tags