Search
Close this search box.

How to append shortcode after content in category in WordPress

To append a shortcode after the content of a post that is in a specific category in WordPress, you can use the the_content filter hook in your theme’s functions.php file. This hook allows you to modify the content of a post before it is displayed on the front-end of your site.

Here’s an example of how you can use this hook to append a shortcode after the content of a post that is in a specific category:

// Append shortcode after content in category
// More snippets at wpunplugged.com 

add_filter( 'the_content', 'append_shortcode_in_category' );
function append_shortcode_in_category( $content ) {
 
    // Check if the post is in a specific category
    if ( in_category( 'category-slug' ) ) {
 
        // Append the shortcode to the content
        $content .= do_shortcode( '[your-shortcode]' );
    }
 
    // Return the modified content
    return $content;
}

In this example, you will need to replace “category-slug” with the slug of the category you want to target, and “[your-shortcode]” with the actual shortcode you want to append to the content.

Keep in mind that this code will only work if you have a shortcode function defined in your theme or a plugin.

Share this post

You might also like...

Forum

bbPress for WordPress Review

bbPress is a great plugin for WordPress that offers a powerful forum solution for WordPress websites. It is well-supported, easy to use, and provides great

Read More »
Pre-built websites in BeTheme
Themes

Betheme for WordPress Review

Betheme is a WordPress theme that has been described as one of the most powerful and versatile themes available for WordPress. In this Betheme for

Read More »

Comment

Your email address will not be published. Required fields are marked *