WordPress Plugin tutorial for beginner from scratch

First of all I want to say, our aim is not making any useful plugin. We will try show  you how to make a plugin only. It is just a complete small plugin. You may see other wordpress plugins tutorial in our site for advance knowledge.

Step-1:
Create a folder inside “wp-content/plugins/” suppose- tp_fblikebutton. So this is our working directory.

Step-2:
Create a file “tp_fblikebutton.php” inside the folder “tp_fblikebutton”. You can give your folder/file name as your needs.

Step-3:
Now open the file tp_fblikebutton.php and put some information regarding your plugin. Remember wordpress will recognize you by this information.

 

/*
Plugin Name: Simple Facebook Like
Plugin URI: http://tutpub.com
Description: It is a simple Facebook like button that will show after ebery single post. There is no option to modify from admin panel.
Author: Shah Alom
Version: 1.0.0
Author URI: http://tutpub.com/
*/

 

Now go to the admin panel and check Plugins. You will see your plugin is in the list of installed plugins.

Step-4:
Now we will create a function that will return Facebook Like button.

 

//Creat the tp_fb_like_button function that will return Facebook likeboutton
//Param $content is nothing here but will use to return content
function tp_fb_like_button($content) {
if ( is_single() ) {
$protocol = $_SERVER[‘HTTPS’] == ‘on’ ? ‘https’ : ‘http’;
$fb_like_url = $protocol.”://”.$_SERVER[‘HTTP_HOST’].$_SERVER[‘REQUEST_URI’];
$content .= ‘<p><iframe src=”http://www.facebook.com/plugins/like.php?href=’;
$content .= $fb_like_url;
$content .= ‘&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=80″ scrolling=”no” frameborder=”0″ style=”border:none; overflow:hidden; width:450px; height:25px;” allowTransparency=”true”></iframe>
</p>’;
}
return $content;
}

 

 Step-5:
Now its time to add an action, so that the above function called to specific time. Such we can call the function after a single post, or in the home page we can call it after/before every post, or in the pages, etc.
Here we will call the Facebook like button every single post. Use the following code:

 

//Add the the_content action that will show the result of tp_fb_like_button method after every single post
add_action(‘the_content’,’tp_fb_like_button’);

 

Facebook Plugin Tutorial for Beginner

Now it’s time to activate the plugin from plugin admin panel and check in the single post page. Please let me know If You find any problem regarding to this plugin. Enjoy!!!

Author Info

Shah Alom

Hi, This is Mohammad Shah Alom, My passion is Programming & Web Development. I am Founder of Micro Solutions Bangladesh. My Facebook profile shahalom1983 & Twitter Profile shahalom_83