The custom Clip installed with WP Clips contains three custom files for adding functions (PHP), scripts (JS/jQuery) and styles (CSS). But, what about page templates? How do you customize an existing template (e.g. front-page.php) or add a new template (e.g. new-page.php)?
Well, there are several methods available, each with its own application –
- Customize the native template and log any changes (existing templates).
- Copy a custom page template from the Clip to the child theme folder (new templates).
- Point directly to a custom template in the Clip (existing and new templates).
Customize the native template and log any changes
Limiting files, functions and calls is always preferable in terms of efficiency. So, if there are only minor changes to an existing template, best practice is to modify the native template directly and log your changes in the custom Clip‘s log.txt file. If the template is ever refreshed or updated, simply refer to your record to reinstate the changes.
Copy a custom page template from the Clip to the child theme folder
If you want to add a new page template and have it appear under Page Attributes > Templates in WordPress admin, you can add the template to your custom Clip directory and set a function to copy the file to your child theme directory.
For example, if adding a new-page.php template, you would add the new template file to your custom Clip directory and the following code to your custom-functions.php file –
//* Copy new page template to active theme folder add_action( 'after_setup_theme', 'clip_new_page_template' ); function clip_new_page_template() { $newdir = get_stylesheet_directory() . '/new-page.php'; if( ! file_exists( $newdir ) ) { $dir = dirname( __FILE__ ) . '/new-page.php'; copy( $dir, $newdir ); } }
In this case, should your child theme ever be refreshed or updated, the new template will automatically be reinstated. This method might also be useful for plugins which permit template overrides within the active theme folder.
Point to a custom template in the Clip (recommended).
For major customizations or new templates, the recommended method is to refer directly to a new template or customized template copy within the custom Clip. This is achieved using the template_include filter hook and a suitable condition to engage the template.
For example, if including a portfolio-page.php template on a page called ‘portfolio’, you would add the new template file to your custom Clip directory and the following code to your custom-functions.php file –
//* Point to new page template in clip folder add_filter( 'template_include', 'portfolio_page_template', 99 ); function portfolio_page_template( $template ) { if( is_page( 'portfolio' ) ) { // this is the condition $new_template = dirname( __FILE__ ) . '/portfolio-page.php'; if ( '' != $new_template ) { return $new_template ; } } return $template; }
Alternatively, if overriding your theme’s front-page.php template, the condition would be –
if( is_front_page() ) {
Note that with this method, the template is included only when the condition(s) is being met and does not appear in admin’s Page Attributes > Templates.
So, there you go!
Adding new templates or customizing existing templates is really very simple. Remember, you can do almost anything within the custom Clip directory – from adding image folders to enqueuing javascript files to referencing alternate templates. WP Clips offers the ideal customizing environment for your child themes and plugins.
Frank Torres says
Badass!! How is WPClips not on the WP website?? It’s just what I was looking for in order to add custom design to already existing child themes. DANKE SCHOEN!!!