• Skip to main content

WP Clips

Update-Safe Code Customizing for WordPress

  • What is a Clip?
  • Docs
    • Installing WP Clips
    • Updating or Upgrading WP Clips
    • Extending WP Clips
    • Customizing a Clip
    • Precoded Clips
      • What are Precoded Clips?
      • Installing Precoded Clips
      • Precoding a Clip
      • Precoded Clip Modules to Extend WP Clips
    • Managing Clips
    • WP Clips Multisite
    • Video Tutorials
  • FAQ
  • Blog
    • WP Clips V3 Released!
    • Adding Custom Code in WordPress Multisite
    • Add or Customize / Replace JS and CSS Files with WP Clips
    • Add or Customize Page Templates with WP Clips
    • Updating and Managing Translations with WP Clips
  • ClipBank

Add or Customize Page Templates with WP Clips

May 05 2016 ·Written by Jon Barratt

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 –

  1. Customize the native template and log any changes (existing templates).
  2. Copy a custom page template from the Clip to the child theme folder (new templates).
  3. 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.

About Jon Barratt

Jon has worked in a variety of creative disciplines over 25 years, including 17 years at the helm of Zynke Design, one of Australia’s most established design studios. He’s been credited on several films, is a qualified strategic intervention coach, and now lives and breathes WordPress, Genesis and WP Clips!

Reader Interactions

Comments

  1. Frank Torres says

    May 25, 2017 at 11:02 am

    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!!!

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • WP Clips
  • WP Clips Multisite

© Copyright 2015 Krolyn Studios · Privacy Policy · Contact Us