Lot of times I get messages in my inbox about simple WordPress questions like how to configure a certain plugin to work with a certain theme so that gave me an idea to write an article about WordPress fundamentals (for newbies).
I made a quick sketch in Paint, of what I feel is a diagram of whole fundamental inner workings of a WordPress blog.
Basically it means that WordPress consists of three elements: WordPress core, plugins and themes. These elements can interact between each other producing final output visible by the end user.
Theme will by default get information from WordPress core, like blog name, URL of the current page, post content, comments etc. It will then display it using PHP functions embedded into the theme. When you see '<?php the_content() ?>' in your theme, you are looking at an example of one such PHP function.
However you can also install plugins to your blog. In most cases plugins will also want to output something to the world.
And basically there are two main ways plugins can do this. They can use (their own, special) PHP functions too like themes, or they can hook to WordPress actions and filters.
Actions and filter hooks are events that get triggered at certain point of time and which the programmer can use to take incoming information, modify it and pass it on.
For example there is a filter called 'the_content' (same name as the function previously mentioned) which allows the programmer to change the content of the post on the fly, and show the modified version on the blog.
And this is the main point I think most people have trouble figuring out.
Let's take for example Similar Posts plugin, which will add a useful list of related articles after the post.
The plugin documentation states you can enable this functionality in two ways. You can edit the theme and add
<?php the_content(); ?>
// insert similar posts now
<?php similar_posts() ?>
line just after 'the_content()' line in your theme. Or in the plugin settings, you can decide that the plugin will automatically add related articles to the end of post (by using the 'the_content' filter to automatically hook into the the_content and show related posts at the end).
The end result is in most cases identical. It isn't in the case when there are several plugins hooking to the_content filter, so your related articles might not be the very last to display. But when you call the plugin function directly below the_content() call in the template file, it is guranteed to display after all content.
So this was a quick surge of thoughts, I hope it has helped someone. Tell me what else would you like to read about.
More like this:
- Smart ways to enhance your blog’s RSS feed
- Ask the WordPress Guru, Q&A #1
- Tweaking WordPress: Home page tweaks
Posted in: WordPress
TAGS:category wordpress hook, fundamental wordpress theme, php the_content, style the_content wordpress, the_content filter, the_content filter end, the_content wordpress hook, using the_content filter, wordpress enable excerpts, wordpress enable exerpts, wordpress filter gallery, wordpress help, wordpress hook, wordpress newbie, wordpress the_content, wordpress the_content encoding, wordpress the_content photo