Global block on post pages

Hello,

I have a global block setup as the side bar on the homepage of kelvintopsetdr.co.uk, How do I get this to apply to all post pages under the news section? So how do I assign that global block to appear on all existing posts and any new posts created?

Thanks in advance
Scott

Hi Scott,

I could see that you’ve already setup a child theme. To achieve that, please add this custom code under functions.php file locates in your child theme:

add_action( 'x_after_the_content_end', 'x_print_navigation', 999 );
function x_print_navigation(){
	if(is_singular( 'post' )){
		echo do_shortcode( '[your-global-block]'  );
	}
}

Don’t forget to replcae the [your-global-block] text with your global block shortcode.

Hope it helps :slight_smile:

Hey,

Thanks for the reply.

I added the code as suggested but has added it to the end of the post rather than being in the sidebar. Sorry I should have been more specific in my original request.

add_action( ‘x_after_the_content_end’, ‘x_print_navigation’, 999 );
function x_print_navigation(){
if(is_singular( ‘post’ )){
echo do_shortcode( ‘[cs_gb id=858]’ );
}
}

Thanks
Scott

Hi Scott,

Does your post uses different sidebars for each? If not, then adding a single text widget to the sidebar with global block shortcode should work. Else, please change that code to this

add_action( 'dynamic_sidebar_after', 'x_print_navigation', 999 );
function x_print_navigation(){
	if(is_singular( 'post' )){
		echo do_shortcode( '[cs_gb id=858]'  );
	}
}

Thanks!

Awesome Rad that works a treat.

Many thanks guys yet again :slight_smile:

You’re most welcome!

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