Changing Beaver Builder Templates in Posts

With WordPress 4.7  “Vaughan” we got  Post Type Templates. On the say day the Beaver Builder theme added this to their change log:

1.5.4 - 12/06/2016

Enhancements

  • Added Full Width and No Header/Footer templates for posts in WordPress 4.7.

This means the post have the same flexibility as post. It does not apply to Custom Post Types

Beaver-Builder-Post-Templates

Make Templates available for Custom Post Types (CPTs)

Beaver-Builder-Post-Templates2

If we want to apply the Beaver Builder (php) templates  to Custom Post Types (CPT's) we need copy the template files from our Parent Beaver Builder theme to our Child theme and add the slug (URL) for our CPTs  to the files (at the top) where it says:

Template Post Type: post, page  Or  Template Post Type: post,

The files are called:  tpl-full-width.php and tpl-no-header-footer.php

Beaver-Builder-Post-Templates3

How to force these templates on all single CPTs without setting them

This brilliant bit of code was supplied by Didou Schol

add_filter( 'template_include' , 'force_template', 99999 );
/**
* force_template on cpt
* @param string $template template-location
* @return string
*/
function force_template( $template ) {

// check if user has set the template manually to be something different than default
if ( $template !== locate_template( array( 'single.php' ) ) ) return $template;

//array of CPT's you want this template to used
$force_template_on_post_type = array( 'products','my_custom_cpt' );

if ( in_array( get_post_type() , $force_template_on_post_type ) ) {
$page = locate_template( array( 'tpl-full-width.php' ) );

// check if we can find this template
if ( ! empty( $page ) ) return $page;
}
// if all else fails, stick with the original template
return $template;
}

Note:  you don't need to add these files  tpl-full-width.php and tpl-no-header-footer.php to the child theme if you are just using one template.

...and a few affiliate links (well you never know)

Beaver Tunnels - Release The Beaver
Best Beaver Builder Add-ons
Ultimate Addons for Beaver Builder
Get Beaver Builder Now!