Adding global block for blog posts

Good morning,
I’d like to use global blocks for blog posts. For example, my latest promo’s would always use the same global block shortcode, and I would like it to appear at the end of all blog posts.

I found this code in your forums, but after adding it to my child theme’s functions.php file, it hasn’t seemed to execute.

Code I copied:
function add_global_post() {
if(is_singular(‘post’)){
echo do_shortcode(’[cs_gb id=1999]’);
}}
add_action( ‘x_before_site_end’, ‘add_global_post’, 10 );

Hi @perfettc,

Thanks for reaching out.

Have you cleared your cache server and browser cache after adding it? And make sure to activate the child theme too. I can’t confirm any of this as I’m not sure where it’s added.

Plus, that code will only add your global block after the footer. Maybe you can change it to something like this.

function add_global_post( $content ) { 
    if(is_singular('post')){
        return $content.do_shortcode('[cs_gb id=1999]');
    }
    return $content;
}
add_filter( 'the_content', 'add_global_post', 9999999999999 );

Thanks!

That syntax worked. Thank you!

You’re welcome!
Thanks for letting us know that it has worked for you.

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