February 19, 2017
Custom code template full width
Author:
David Waumsley, Didou Schol
Description:
tpl-full-width.php tpl-no-header-footer.php
Copy these two files to your child theme, open them and add the slug of your custom post like this:
Do the same to the other file.
Now to enforce this template on all your custom posts add the following in your functions.php:
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( 'books', 'cars', '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;
Kind:
PHP