Hi @amalaia11,
What are you exactly trying to achieve? What should the plugin/shortcode do ?
Ideally, as far as I know shortcodes are added in the editor to achieve a specific functionality. Are you looking for a plugin that will automatically add this short code at the end of all posts in all categories?
I have a blog with many posts in category A. I use a plugin (kodex like plugin) which let’s users vote about posts. This plugin has settings to activate voting on shortcode or on all posts.
At the moment I use it on “all posts” which is fine but now I want to add posts in another category without the vote button. I do it with custom css “.hide” for the posts which I don’t want that vote button but thats not the best practice…
Ideally I want to use the plugin only with shortcodes, but I have a big number of posts which I would have to edit manually…
Hello @amalaia11,
You can try something like this
“yourcategory” is the category term for which you want to display things
add_filter('the_content','shortcode_generator');
function shortcode_generator($content){
global $post;
if(has_category('yourcategory',$post)){
$content.='[yourshortcode]';
return $content;
}
else{
return $content;
}
}
Add this code in your theme’s functions.php.Hope this will solve your purpose.