GenerateWP Makes It Easy To Create WordPress Code Snippets

GenerateWPEven for developers with a modicum of PHP experience, developing for WordPress can be tricky. GenerateWP is a useful tool that makes it easier to create snippets of PHP code that can be added to WordPress plugins, to the functions.php file, and anywhere else that you might want to make a tweak to add functionality to your WordPress site.

GenerateWP is a web app — users choose the type of functionality they want to create code for, fill in a few options, and the app will spit out a code snippet that can be pasted into a plugin or theme file. Among the snippets that can be generated are code for custom post types, menus, and shortcodes, but it’s the newly added ability to generate code that uses WordPress hooks that interest me the most.

If you really want to get into WordPress development, you have to understand how hooks work, and how they can be used by developers to change the behavior of WordPress without tampering with WordPress Core — never a good idea. You can think of a hook as a special function that is triggered when a specific action takes place — when a post is published for example. When the hook is triggered, it will run other functions that are associated with that hook. There are hooks that are run when an article is published, when pages are generated, and so on — hooks are how plugin developers “hook into” the WordPress application. They write functions that carry out an action (or filter data), and link them up to a specific hook to trigger them at a specified point in the execution of the WordPress app.

Now, hooks aren’t all that difficult to use once you get your head around how they work. A simple example looks like this (from the WordPress Codex guide to hooks):

function email_friends($post_ID) {
$friends = 'email hidden; JavaScript is required,email hidden; JavaScript is required';
mail($friends, "sally's blog updated",
'I just put something on my blog:');
return $post_ID;
add_action('publish_post', array('emailer', 'send'));

The first section specifies the function. The last line uses the “add_action” function to tell WordPress which hook should trigger the function (in this case ‘publish_post’).

If you know PHP, this isn’t all that complicated, but one problem with WordPress hooks is discoverability. The excellent database of WordPress hooks by Adam Brown is an essential resource, but GenerateWP’s new hooks generator makes it much easier to find the hook you want, learn about it, and easily generate the necessary code.

I know there are plenty of WordPress developers out there who disdain tools like WP Generate, but to my mind, it’s a great educational resource to help less-experienced WordPress developers get to grips with plugin and theme development — and even the experts can take advantage of the productivity boost provided by a tool that makes it straightforward to find and generate the right code without a trawl through the documentation.

Matthew Davis is a technical writer and Linux geek for Future Hosting.

Dedicated Server Special

Take advantage of our Double RAM offer on the E3-1230v2 4 x 3.30GHz+HT server! Only $134.95 per month. Managed and Unmanaged options available at checkout.