Add Shortcodes to Template files?

I’m trying to create a custom post template for feeds of a certain category of posts, but more of an X template with global blocks as opposed to a wordpress php file… I’ve already got the template set up with X, and would just like to overwrite everything else when any child category of a certain parent category is being displayed.

I created a child theme and have the following in functions.php:

add_filter( 'single_template', function ( $single_template ) {

$parent     = '11'; //Only CTIDE category
$categories = get_categories( 'child_of=' . $parent );
$cat_names  = wp_list_pluck( $categories, 'name' );

if ( has_category( 'CTIDE' ) || has_category( $cat_names ) ) {
    $single_template = dirname( __FILE__ ) . '/single-ctide.php';
}
return $single_template; 

}, PHP_INT_MAX, 2 );

From there I’m wondering if I can just insert the global blocks (just a header and footer) into my feed-ctide.php template in order to avoid having to get too in the weeds with a new template php file.

Any advice appreciated. Thanks

Hello @PRCPTIONtravel,

Thanks for writing in! As long as you have get_header() and get_footer(), the default header of the theme should display. Please check out the codex here:

And if you want to add a global shortcode using PHP, you use this:

<?php echo do_shortcode('[cs_gb id=123]'); ?>

where [cs_gb id=123] is the Global Block shortcode which you can get in X > Global Blocks.

Please be advised that what you are trying to do is beyond the scope of our support. We can only provide bits of code to get you started with. Keep in mind that custom code might lead to some issues which you will have to check and troubleshoot on your own.

Best Regards.

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