Make WordPress Development Easier, Use WordPress Helpers

Building anything from the ground up is always time-consuming. That’s why people like to use templates, ready-made solutions, frameworks and other things that can cut their work time in half without sacrificing quality, or better yet, even improving quality.

The thing is that if you have some pre-made solution at your disposal then you don’t have to worry about all the mundane tasks and details you’d have to take care of when creating things from scratch. And when you don’t have to do the mundane, you can focus on doing the creative.

That’s why today, I want to talk about making our lives easier when working with WordPress by using some handy helpers.

Generate stuff!

Let’s start with one of the top discoveries in the recent months – GenerateWP. This is an online tool created by a guy named Rami. He emailed me back in February and sent me a brief description of GenerateWP.

In short, it’s a set of very cool fill-in-the-blank WordPress generators for developers and other people who like to tweak their sites in general.

In order to use it, all you have to do is provide the details of the outcome you want to achieve and click the Update Code button. As a result, you will get a piece of WordPress code that you can then take and use in your work.

The main value of this tool is that you don’t have to worry about being up-to-date with the modern WordPress coding standards by yourself. You can just focus on the core of the functionality you need and leave the code structure and compatibility to GenerateWP.

In his email, Rami also promised that the tool will be kept up-to-date to make everyone happy.

Currently, the things GenerateWP can help you with are:

  • Setting up your wp-config.php file. You can set the database connection, take care of the security, tune up the performance settings, set the language, turn on the debug mode and much more.
  • Taxonomy generator. Create your own custom taxonomies.
  • Post type generator. Create your own post types.
  • Post status generator. Create custom post statuses. Actually, post statuses are something I couldn’t get done by hand a while ago (I needed them for better cooperation with my editor). I don’t know why, but every tutorial/guide online seemed to have some errors. GenerateWP was the only one to do it right.
  • Sidebar generator. Also known as the widget area generator. It gives you optimized code you can then place in your functions.php.
  • Menu generator. Generate some custom menu areas.
  • Theme support module. Helps you set the basic parameters of your theme like the content width, feed links, post formats, thumbnails, background and header.
  • Shortcode generator. Create your own shortcodes…because why not?

I’m sure that GenerateWP will bring even more cool features in the future so I encourage you to pay the site a visit every once in a while to see what’s going on.

Custom page templates

Creating some custom page templates is probably one of the most common ways of extending a theme.

Although there are many guides on the web on how to do this (even one of my own here: how to build a custom page template – check it out to get all the whys and hows on custom templates), I’ve decided to give you the essential and simple three-step tutorial on building custom templates – aka the helper version.

1. Create a new PHP file in your theme’s folder.

2. Put this content in it:

<?php
/* Template Name: Name of Your Custom Template */

// copy and paste your page.php contents here
?>

3. Modify the part you’ve copied and pasted.

I am using the above template myself for every custom page I create. The thing I’ve noticed is that most custom page templates are just a little different than the standard page.php template anyway. So why not make our work easier and build upon it from the get-go?

Child themes

(Here’s our complete guide to child themes.)

Honestly, child themes are by far the best and the safest way of modifying any theme created by someone else. This is also the recommended way of working with our themes and that’s why we always provide a pre-made child theme along with every theme from our theme shop.

Once you get a grasp on how child themes work you can create the core of a new child theme very quickly:

1. Create a new theme folder in wp-content/themes.

2. Create a new style.css file and put this in it:

/*
Theme Name: Name of Your Child Theme
Theme URI: http://yoursite.com/
Description: Your description.
Version: 1.0
Author: so and so
Author URI: http://yoursite.com/
Template: parent_theme’s_folder
*/

@import url(“../parent_theme’s_folder/style.css”);

The big CSS comment provides some info about your new theme. The @import rule tells your theme to work on the parent theme’s CSS stylesheet. That way you don’t have to create the style for your child theme from scratch.

Two more details:

  • If you create a new functions.php file, it will be loaded along with the original functions.php. The new one will be loaded first.
  • Every standard template file you create (e.g. page.php, single.php, etc.), will replace its original namesake.

New widgets

Although widgets are one of the simplest add-on elements in WordPress, creating even the simplest widget surprisingly requires quite a bit of code.

First of all, we’re creating a widget as a plugin, so start by creating a new PHP file in your wp-content/plugins folder.

Then, consider the following template. It’s a simple placeholder widget that only has a title and a place where you can include your custom widget code (indicated with //WIDGET CODE GOES HERE).

<?php
/*
Plugin Name: Your Widget’s Name
Plugin URI: http://yoursite.com/
Description: What the widget does
Author: so and so
Version: 1.0
Author URI: http://yoursite.com/
*/

class MyNewWidget extends WP_Widget
{
function MyNewWidget()
{
$widget_ops = array(‘classname’ => ‘MyNewWidget’, ‘description’ => ‘What the widget does’ );
$this->WP_Widget(‘MyNewWidget’, ‘Widget’s title in WP Admin’, $widget_ops);
}

function form($instance)
{
$instance = wp_parse_args( (array) $instance, array( ‘title’ => ” ) );
$title = $instance['title'];
?>
<p><label for=”<?php echo $this->get_field_id(‘title’); ?>”>Title: <input id=”<?php echo $this->get_field_id(‘title’); ?>” name=”<?php echo $this->get_field_name(‘title’); ?>” type=”text” value=”<?php echo attribute_escape($title); ?>” /></label></p>
<?php
}

function update($new_instance, $old_instance)
{
$instance = $old_instance;
$instance['title'] = $new_instance['title'];
return $instance;
}

function widget($args, $instance)
{
extract($args, EXTR_SKIP);

echo $before_widget;
$title = empty($instance['title']) ? ‘ ‘ : apply_filters(‘widget_title’, $instance['title']);

if (!empty($title))
echo $before_title . $title . $after_title;;

//WIDGET CODE GOES HERE

echo $after_widget;
}
}
add_action(‘widgets_init’, create_function(”, ‘return register_widget(“MyNewWidget”);’));
?>

(The original version of the code comes from James Bruce.)

New plugins

Actually, I’ve already shared the template for a new plugin above when discussing widgets. But just so everything is clear, here are the only requirements for a new plugin:

  • A PHP file in the wp-content/plugins folder (or in a plugin’s sub folder).
  • A readme.txt file about the plugin (not mandatory but recommended).

Your PHP file has to contain the following header:

<?php
/*
Plugin Name: Your Plugin’s Name
Plugin URI: http://yoursite.com/
Description: What the plugin does
Author: so and so
Version: 1.0
Author URI: http://yoursite.com/
*/
?>

When it comes to the rest of your plugin’s PHP file, the sky really is the limit and there’s nothing else I can point out as part of the “essential template.”

Let me just mention that the most popular way of building plugins is to create a bunch of PHP functions and then execute them through WordPress’ hooks and actions (add_action();).

The readme.txt file has a standardized structure, which you can view here.

That’s it for this set of helpers and templates. I hope I’ve managed to cover all the most essential add-ons and tweaks being done to WordPress sites. Or did I miss something important?

there are 2 comments added

  1. mishkin 6th June 2013

    GenerateWP is interesting to say the least. Never heard of it before this article. Thanks for posting.

  2. rachgaz 2nd July 2013

    Great article. Thanks for the heads up on GenerateWP too - definitely going to take a good look at that.

(optional field)

HTML tags are not allowed.

Reset fields

back to top