• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Filter [post_categories] / [post_terms] shortcodes to exclude categories

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Filter [post_categories] / [post_terms] shortcodes to exclude categories

This topic is: resolved

Tagged: filter, get_the_category_list, post_categories

  • This topic has 4 replies, 2 voices, and was last updated 9 years, 6 months ago by AJD.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • June 29, 2016 at 4:35 pm #188616
    AJD
    Member

    Hi,

    I'm stuck trying to filter the [post_categories] shortcode to exclude some specific categories from display. I'd like to use the ID to do this.

    Is there a filter for this?

    EDIT: I realize I also need to filter [post_terms], because I need to do the same thing for a custom post type/taxonomy.

    Thanks
    AJ

    June 30, 2016 at 12:59 am #188632
    Brad Dalton
    Participant

    You can create a custom version of the post categories shortcode and then filter the post meta in the entry footer

    Use the original function as a guide.

    add_shortcode( 'post_categories', 'genesis_post_categories_shortcode' );
    /**
     * Produces the category links list.
     *
     * Supported shortcode attributes are:
     *   after (output after link, default is empty string),
     *   before (output before link, default is 'Tagged With: '),
     *   sep (separator string between tags, default is ', ').
     *
     * Output passes through 'genesis_post_categories_shortcode' filter before returning.
     *
     * @since 1.1.0
     *
     * @param array|string $atts Shortcode attributes. Empty string if no attributes.
     * @return string Shortcode output
     */
    function genesis_post_categories_shortcode( $atts ) {
    
    	$defaults = array(
    		'sep'    => ', ',
    		'before' => __( 'Filed Under: ', 'genesis' ),
    		'after'  => '',
    	);
    
    	$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( '<span %s>', genesis_attr( 'entry-categories' ) ) . $atts['before'] . $cats . $atts['after'] . '</span>';
    	else
    		$output = '<span class="categories">' . $atts['before'] . $cats . $atts['after'] . '</span>';
    
    	return apply_filters( 'genesis_post_categories_shortcode', $output, $atts );
    
    }
    

    Or, use the genesis_post_categories_shortcode filter to modify the default.


    Tutorials for StudioPress Themes.

    June 30, 2016 at 7:18 am #188643
    AJD
    Member

    Hi, Thanks,
    I did find the code and filter, however am at a loss of how to proceed from there.

    June 30, 2016 at 8:43 am #188661
    Brad Dalton
    Participant

    Understand. You'll need a custom filter function written for what you want unless you can find an existing tutorial already published which includes the code you need.


    Tutorials for StudioPress Themes.

    June 30, 2016 at 9:05 am #188666
    AJD
    Member

    Hi, I landed up creating a customized get_the_terms_list() function to use in a custom post_info shortcode. (For the custom taxonomy)

    Cheers!

  • Author
    Posts
Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Filter [post_categories] / [post_terms] shortcodes to exclude categories’ is closed to new replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble