Adding 2 global blocks to post and archive page

hi there,

i foud the code to add aglobal block to the post page in this post:

it wokrs when i add one global block.
i need to add 2 global blocks. one on below the header and one on bottom after the blog post conent

header
global block
post image
post text
global block
footer

is it also possible to add the global blocks to the archive page?

thanks in advance for your help.

cheers

Hello Harald,

Thanks for writing in!

Since you are using Pro theme, you can use this code to add a global block for your single posts and archive pages:

// Right after the header
function add_block_before_the_content_begin() {   
    if( is_singular('post') || is_achive() ){
        echo do_shortcode('[your global block shortcode]');
    }
}
add_action( 'x_after_masthead_end', 'add_block_before_the_content_begin');

// Right before the footer
function add_block_after_the_content() {   
    if( is_singular('post') || is_achive() ){
        echo do_shortcode('[your global block shortcode]');
    }
}
add_action( 'x_before_colophon_begin', 'add_block_after_the_content');

Make sure to insert your Global block shortcode in the code above.

1 Like

hi there,

it does work sometimes, but sometimes there is a fatal error:

Fatal error: Uncaught Error: Call to undefined function is_achive() in /var/www/web22826263/html/cr68/gatten/wp-content/themes/pro-child/functions.php:157 Stack trace: #0 /var/www/web22826263/html/cr68/gatten/wp-includes/class-wp-hook.php(288): add_block_before_the_content_begin(’’) #1 /var/www/web22826263/html/cr68/gatten/wp-includes/class-wp-hook.php(312): WP_Hook->apply_filters(’’, Array) #2 /var/www/web22826263/html/cr68/gatten/wp-includes/plugin.php(478): WP_Hook->do_action(Array) #3 /var/www/web22826263/html/cr68/gatten/wp-content/themes/pro/framework/views/header/masthead.php(28): do_action(β€˜x_after_masthea…’) #4 /var/www/web22826263/html/cr68/gatten/wp-content/themes/pro/framework/functions/frontend/view-routing.php(182): include(’/var/www/web228…’) #5 /var/www/web22826263/html/cr68/gatten/wp-content/themes/pro/framework/functions/frontend/view-routing.php(55): X_View_Router::render(’/var/www/web228…’, NULL, true) #6 /var/www/web22826263/html/cr68/gatten/wp-content/themes/pro/framework/functions/frontend/vie in /var/www/web22826263/html/cr68/gatten/wp-content/themes/pro-child/functions.php on line 157

do you have a solution to fix this?

after header global block: [cs_gb id=429]
before footer global block: [cs_gb id=259]

thanks in advance

credentials in secure note

hi,

i figured it out. it was the is_achive() i replaced it with is_home()

thanks again for your help

cheers

We’re glad that you figured it out, Harald.

1 Like

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