WordPress Theme Specific Plugin

In addition to using plugins, some customers like to further customize their theme. This tutorial explains the correct way to add modifications to your AppThemes theme (or any theme).

Some Benefits

Why would you want to build a custom plugin?

  • Your mods are portable and can technically be used across any theme
  • Your mods don’t get overwritten when there’s a theme update
  • You don’t need to build out an entire child theme

The Wrong Way

Editing the theme files and making changes there. What’s wrong with that? Well, the next time you update your theme to a new version, ALL your custom code changes are blown away. What a waste!

The Right Way

Create a theme-specific plugin and put all your customizations in there. That way, your changes aren’t overwritten on theme updates. It’s also much easier and less intimidating than creating a child theme and it’s only one file to manage.

Ok, now that you understand the logic behind this, let’s get started!

Create Your Plugin

Put on your developer’s hat and let’s get started. In this example, we’re going to write a custom plugin for the Vantage theme.

  • Open your file explorer and navigate to your website directory (e.g. /www/vantage/wp-content/plugins/)
  • Create a new directory called, vantage-custom-code
  • Go into that new directory and create a file called, vantage-custom-code-plugin.php
  • Edit that new file in any text editor and paste in the below template code
  • Change the author and author uri to your information
<?php 
/**
 * Plugin Name: Vantage Theme Custom Code
 * Description: Custom code used in the AppThemes Vantage theme.
 * Version: 1.0.0
 * Author: Me
 * Author URI: http://www.mydomain.com
 */
 
/* Add Your Functions Below this Line */

Now, any new functions you wish to add should now be placed in here! Well, that’s great but what sort of things could I change?

You can override different styles, existing functions, or add a completely new function.

Here’s a simple example of a custom function which should get you started. It removes the WordPress version number from your website’s source code which can deter hackers from trying to penetrate your site (e.g. if a specific WordPress version has a vulnerability, they can target you).

/**
 * Removes the WordPress version number from the html head and rss feed.
 *
 * @since 1.0.0
 *
 * @param string $type The generator output.
 */
function my_remove_wp_version( $type ) {
    return false;
}
add_filter( 'the_generator', 'my_remove_wp_version' );

Here’s the final result of what your plugin file should look like.

<?php 
/**
 * Plugin Name: Vantage Theme Custom Code
 * Description: Custom code used in the AppThemes Vantage theme.
 * Version: 1.0.0
 * Author: Me
 * Author URI: http://www.mydomain.com
 */
 
/* Add Your Functions Below this Line */
 
/**
 * Removes the WordPress version number from the html head and rss feed.
 *
 * @since 1.0.0
 *
 * @param string $type The generator output.
 */
function my_remove_wp_version( $type ) {
    return false;
}
add_filter( 'the_generator', 'my_remove_wp_version' );

That’s it! Now save your file and upload it to your website (if you haven’t already). The next time you visit your site, view your source code and you should no longer see the following entry:

<meta name="generator" content="WordPress 4.6.1" />

That’s just the tip of the iceberg. You can do more theme-specific stuff instead of tweaks to WordPress. That goes outside the scope of this tutorial, however.

Like this tutorial? Subscribe and get the latest tutorials delivered straight to your inbox or feed reader.

Your rating: none
Rating: 5 - 3 votes

Popular Add-ons

WP Smart Export

WP Smart Export

A highly customizable WordPress data exporter plugin.


(7)
$19

Authorize.Net

Easily start accepting online payments via credit card and e-check.


(4)
$39

2Checkout

Accept up to eight payment methods, fifteen languages, & twenty six…


(4)
$39