WordPress Plugins

There are many situations where we want to go “out of the box” to achieve some of the things we want for our website.

Say for example, we want to use Google’s Analytics that keeps track of visitors, referrers, popular entry pages, popular keywords etc for our site. Google gives a snippet of code to be placed at the bottom of your site’s code so that every hit to your website is recorded on their server. This way Google can provide various reports and analysis that can help you tune your website.

If we add the code that google provides, into the footer.php, then we are done. but whenever we change the theme, we have to make sure we copy and paste this code in that theme’s footer.php.

How cool will it be if we pasted the code only once regardless of the theme that we are using?
That’s exactly the purpose of installing a Google Analytics Plugin and activating it !

Now you have an idea of what a plugin is useful for.

Each Plugin is a collection of one or more files that reside on http://your-website-name/wp-content/plugins/ folder.

There are also a lot of Plugins available over the internet, that gives additional functionality to the WordPress. You can download and install them on your website. Read more at http://wordpress.org/extend/plugins/.

How does the Plugin hook up into certain portion of the theme ?

In our google analytics plugin example, the plugin needs to attach some code at the footer of any theme. WordPress provides a function called “wp_footer()” that can be called in the footer.php file.
The plugin can attach itself to this function call, and can execute as long as each theme that we use makes a call to wp_footer() from its footer.php

ok. Now you understood that.

What other hooks that WordPress provides ?

There are other hooks that a plugin can take advantage of.

  1. wp_head() – is called from header.php, within <head> and </head> and any plugin can inject their code by attaching itself to this function.
  2. wp_meta() – is called from the sidebar.php where it presents a list of links such as “Login”, “Valid XHTML” etc. A plugin can attach itself here so it can emit other links it wants.
  3. wp_footer() – is called from footer.php, as we discussed previously in our example.
  4. add_action($hook_name, $function_name) – is another way a plugin can hook itself into some action.
    For example, If you look at the “Subscribe to Comments” plugin’s code, it will add an action to the “comment_form” hook so that it can show a checkbox for users to be able to subscribe to the comments.

Wow ! Thats a lot to learn in one day. Let’s go for a break and continue in our next session.
Enjoy !

Please use the sidebar for navigating within the Book.