Adding Code to Every Page in a Certain Cat

Hi, is it possible to add shortcode to the bottom of every page in a particular category, before the comments? if category == ‘mycat’ … insert short code above comments.

Hello @GGMM,

You can make use of the x_before_the_content_end hook then the has_category Wordpress function just like this:

add_action( 'x_before_the_content_end', 'x_after_post_content', 999 );

function x_after_post_content() {

	if(is_singular( 'post' ) && has_category( 'the_category_slug' ) ) {
		echo do_shortcode('[your_shortcode]');
	}

}

Kindly note that since this is a custom code that changes the default behavior/display of the theme, you will be responsible to maintain or update the code in case you require further changes or if the code stops working in future updates. If you are uncertain how to proceed, it would be best to get in touch with a developer.

Hope this helps.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.