How To Override Simple Staff List Template Files With A Plugin

If you don’t want to (or can’t) add your single Staff Member template overrides to your theme, you can do so by writing a simple WordPress plugin. This tutorial will walk you through the steps to customize the single Staff Member template files using your own custom plugin.

First you need to create a folder for your plugin, let’s call it my-simple-staff-list-customizations, with a file named my-simple-staff-list-customizations.php.

If you want to read about WordPress plugins are written, this is a great place to start.

Add this code to my-simple-staff-list-customizations.php to tell WordPress that this is a plugin. Feel free to change the name, description, or author bits.

<?php
/**
 * Plugin Name: My Simple Staff List Customizations
 * Description: Customizations for Simple Staff List
 * Version: 1.0
 * Author: Brett Shumaker
 * Author URI: https://brettshumaker.com
 * License: GPL2
 **/

Once you’ve done this, congratulations, you’ve written a WordPress plugin! It obviously doesn’t do anything yet, so next, we need to tell Simple Staff List that we want it to look in our plugin for custom template files. We can do this by using the sslp_get_template_part filter. Add this code to my-simple-staff-list-customizations.php.

define( 'SSLPC_PATH', plugin_dir_path( __FILE__ ) );

// Tells Simple Staff List to look in this plugin for template customizations instead of the theme
add_filter( 'sslp_get_template_part', 'sslpc_templates', 10, 2 );
function sslpc_templates( $template, $slug ) {

	if ( file_exists( SSLPC_PATH . 'sslp-templates/' . $slug . '.php' ) ) {
		$template = SSLPC_PATH . 'sslp-templates/' . $slug . '.php';
	}

	return $template;

}

define( 'SSLPC_PATH', plugin_dir_path( __FILE__ ) );
This defines the path to the plugin folder so we can use it later.

add_filter( 'sslp_get_template_part', 'sslpc_templates', 10, 2 );
Here, we hook the sslpc_templates function to our filter with a priority of 10 and we tell it to expect 2 arguments. $template is the path to the template file being requested, and $slug is the slug of the template being requested (staff-bio, or global/wrapper-start, etc.).

The sslpc_templates function checks to see if a file exists in our plugin’s sslp-templates folder (we haven’t made it yet) for the $slug being requested. If the file exists, it returns the path to the plugin’s template file – otherwise, it returns the existing path.

So now that we’ve told Simple Staff List to also look in our new plugin for template files, all that’s left is to make a folder named sslp-templates inside of our new plugin. Then, we’ll add any files we want to override. For example, if we wanted to change the way the staff email address is displayed, we’d make a folder our-new-plugin-folder/sslp-templates/single-staff-member/ and copy the staff-email.php file from the Simple Staff List plugin into that folder and then make our changes. It’s important to keep the original folder structure when overriding these template files.

That’s all there is to it to making a custom plugin to contain all of your overrides to Simple Staff List single Staff Member template files. I’ve made a simple example plugin if you’d rather start with that instead of writing your own plugin and you can download it here.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Brett Shumaker

Subscribe now to keep reading and get access to the full archive.

Continue reading