Adding global block directly below navbar

Hello,

We are wanting to ad a global block directly below the navbar of blog posts.

Like the top of our other pages:

So far we have been able to add the global block to the posts, but it appears below the feature image and title.

We are using the following code in the child functions.php.

function add_global_post() {
if(is_singular(‘post’)){
echo do_shortcode(’[cs_gb id=10887]’);
}}
add_action( ‘x_before_the_content_begin’, ‘add_global_post’, 10 );

How do we acheive this?

Thanks so much!

Hello @PagnatoKarp,

Thanks for writing in!

I suggest you to copy /wp-content/themes/x/framework/legacy/cranium/headers/views/global/_navbar.php to /wp-content/themes/x-child/framework/legacy/cranium/headers/views/global/_navbar.php.

After that replace the code with following:

<?php

// =============================================================================
// VIEWS/GLOBAL/_NAVBAR.PHP
// -----------------------------------------------------------------------------
// Outputs the navbar.
// =============================================================================

$navbar_position = x_get_navbar_positioning();
$logo_nav_layout = x_get_logo_navigation_layout();
$is_one_page_nav = x_is_one_page_navigation();

?>

<?php if ( ( $navbar_position == 'static-top' || $navbar_position == 'fixed-top' || $is_one_page_nav ) && $logo_nav_layout == 'stacked' ) : ?>

  <div class="x-logobar">
    <div class="x-logobar-inner">
      <div class="x-container max width">
        <?php x_get_view( 'global', '_brand' ); ?>
      </div>
    </div>
  </div>

  <div class="x-navbar-wrap">
    <div class="<?php x_navbar_class(); ?>">
      <div class="x-navbar-inner">
        <div class="x-container max width">
          <?php x_get_view( 'global', '_nav', 'primary' ); ?>
        </div>
      </div>
    </div>

  </div>

<?php else : ?>

  <div class="x-navbar-wrap">
    <div class="<?php x_navbar_class(); ?>">
      <div class="x-navbar-inner">
        <div class="x-container max width">
          <?php x_get_view( 'global', '_brand' ); ?>
          <?php x_get_view( 'global', '_nav', 'primary' ); ?>
        </div>
      </div>
    </div>
    <?php echo do_shortcode("[your-global-block]"); ?>

  </div>

<?php endif; ?>

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

Before proceeding please make sure that child theme is setup in accordance with following resources:

Download Child theme from following source: https://theme.co/apex/child-themes

Please take a look at following article to setup child theme:

Please note that above solution is to help you get started. In case of any issues, it will be outside the scope of support we can offer.

Thanks.

Hello again,

Thanks very much for the information.

For future reference, the directory that the navbar.php needs to be added to is /wp-content/themes/x-child/framework/views/global/, not the directory listed in the previous post.

While this is a start and is basically working, there is one main issue.

This global global block need to be on blog posts only. Not on the blog index, or any other pages on the site (we use various global block at the top of various pages).

While we have it working perfectly on the blog posts (https://pagnatokarp.staging.wpengine.com/ceo-founders-how-to-defer-taxes-when-selling-a-business/), here is how it appears on the blog index:

Here is how it is behaving on regular pages (creating a duplicate of the global block that is already on those pages)

or creating spacing that should not be there on pages with different global blocks at the top of the page

Thanks again for any help or suggestions.

Hi @PagnatoKarp,

The custom function you showed above should work, you just need to change your hook.

function add_global_post() { 
if(is_singular('post')){
echo do_shortcode('[cs_gb id=10887]');
}}
add_action( 'x_after_view_global__slider-below', 'add_global_post', 10 );

Actions and Filters in X/Pro

Please remove the custom _navbar.php or navbar.php on your child theme to avoid conflict.

Hope it helps,
Cheers!

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