The far most frequent question I get regarding WordPress development is “What is filter and hooks?”
. So here I thought I explain how these can be used developing a plugin.
Filters can be seen as just – filters, mostly for filtering the content of a post such as the title, content text or comments
in some countries. They are of appeal to a group of menagonists; some may act both centrally and peripherally, viagra pills.
. The most importent filter when developing plugins is “the_content”, this filter is used to pass the content of the post or plugin test to a specific function. Let me do an example.
Say I’d like to change some words in my posts and titles to something else, for example change all “Microsoft” to “Apple”. Let’s start by creating a new file, I’ll call this plugin.php and save it to your wp-content/plugins directory.
First we tell WordPress the plugin name and it’s version, this is what you see in the Manage Plugins in WordPress admin interface. The add_filter function tells WordPress to pass “the_content” of the post to my_function for filtering before echoing it to the page. This do not apply to the post title so we have to add another filter, “the_title” tells WordPress to pass the post title to my_function before echoing, and as you can se all we do is a simple string replacment in my_function.
So now all the Microsoft is changed to Apple in every post and page. Removing this plugin restores the string to it’s orginal . This plugin does not alter the text in the database it only filters the content
. There’s a lot of filter to use in WordPress and this is a start for any “WordPress Plugin developer Wannabe”. This code also replaces text within html tags so your layout might break so you shouldn’t use this on a production site, it merly shows the power of filter.
If you want to check out the filters go and visit the WordPress filter/hooks database.