How do I use php to grab an x theme section or page and display it above the header navbar?

I’m using X theme with Renew. I don’t want to use Revolution Slider… I’d like to just have a section or a page just be displayed above the header for the home page only.

Hello Michael,

Thanks for writing in!

Because what you are trying to accomplish requires a template customization, we would highly to suggest that you use a child theme. This allows you to make code changes that won’t be overwritten when an X update is released.

After the child theme is set up, please add the following code in your child theme’s functions.php file

// Add custom global block
// =============================================================================
function custom_global_block() { ?>
  <?php if ( is_home || is_front_page()() ) : ?>
    <div class="custom-shortcode">
      <?php echo do_shortcode('[cs_block shortcode here]'); ?>
    </div>
  <?php endif; ?>
<?php }
add_action('x_before_view_global__slider-above', 'custom_global_block');
// =============================================================================

You will then have to go to X > Global Blocks and create a block that you want to display above the header. Once you have created it, copy the global shortcode and replace the [cs_block shortcode here] with the correct one.

Hope this helps.

Thanks RueNel!
This did the trick. The if statement just needed to change slightly to only show this section on the home page and not on every page.
<?php if ( is_front_page() ) : ?>

Hey Michael,

The code had a syntax error in the If check, you can update the code with the following one:

// Add custom global block
// =============================================================================
function custom_global_block() { ?>
  <?php if ( is_home() || is_front_page() ) : ?>
    <div class="custom-shortcode">
      <?php echo do_shortcode('[cs_block shortcode here]'); ?>
    </div>
  <?php endif; ?>
<?php }
add_action('x_before_view_global__slider-above', 'custom_global_block');
// =============================================================================

Cheers!

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