Very Basic first step to write a word press plug in
To start our first plug in ,first we must have a plan what our plug in do on blog. However this topic we continue on later. To write a plug in ,we have to get idea of our plugin name that suggests to it.Here we write a plugin that filters the post or page title and content.
That replaces “hello” to “hello Mahesh world”.And i named it my-plugin
Download Demo
Manage Files
create a folder called “my-plugin” in the word press plugin directory.
Add a file called “my-plugin.php” and code in that is just PHP tags.
Remember plugin directory and plugin name should be same.
<?php ?>
After Adding code go to your admin panel and click the link installed on the All tab of plugins we don’t get our plug in listed there!!!.
Getting listed our plug in on the plug ins page
Yes,absolutely we didn’t great job by adding only file . To get listed we have to add a plug in description and its name.Add below comment code to your plug in page.
/*
Plugin Name: My Plugin
Plugin URI: http://maheshchari.com/
Description: Description of my plugin
Author URI: http://maheshchari.com/
*/Adding functionality to plug in
Here plugin works as filtering post content and post title while it displayed. Logic is simple for that we use str_replace function.
Word press had to action filters for displaying title,content . they are the_content,the_title.we add our function to this filters by default priority.
<?php /* Plugin Name: My Plugin Plugin URI: http://maheshchari.com/ Description: Description of my plugin Author URI: http://maheshchari.com/ */ function my_plugin_filter($text){ $text=str_replace('Hello','<b>hello Mahesh</b>',$text); return $text; } add_filter('the_content','my_plugin_filter'); add_filter('the_title','my_plugin_filter'); ?>
Testing plug in
Now we add a post that contains Hello word in the post title and in the content of it.
It shows this word as Hello Mahesh on title and content.
Download Demo
Now we successfully created our plugin and next adding sub menu on admin panel of word press .
Popularity: 2% [?]









Related Articles
No user responded in this post
Leave A Reply