Thursday, 26 December 2013 15:11

how to create wordpress plugin

Written by 
Rate this item
(0 votes)
Following are the steps to create your first wordpress plugin.After you
successfully complete these steps, you are able to understand and
learn how to create wordpress plugin
Step-1:

Create a folder with the name of your plugin and inside it place a php
file with the same name as plugin name, like my-first-plugin.php. First compulsory
content will be -
/*Plugin Name: my first pluginPlugin
URI: http://extensions.programminghelp24.com/
Description: descriptionAuthor: mitsol   
Version: 1.0Author
URI: http://extensions.programminghelp24.com/
License: GPLv2 or later */  


Code details - It describes your plugin name and description.without it
plugin will not work

Step-2:
Add more content as follows -

function my-first-plugin-activation() {}

register_activation_hook(__FILE__, 'my-first-plugin-activation');

function my-first-plugin_deactivation() {}

register_deactivation_hook(__FILE__, 'my-first-plugin-deactivation');

add_action('wp_enqueue_scripts', 'my-first-plugin-scripts');

function my-first-plugin-scripts() {    
 wp_enqueue_script('jquery');      
wp_register_script('mitsol_feed_javascript', plugins_url('js/my_js.js', __FILE__), array("jquery"));
 
wp_enqueue_script('mitsol_feed_javascript');
}
Code details - here my-first-plugin-activation() function codes will
run when plugin is activated, likewise my-first-plugin-deactivation()
will run when plugin is deactivated

here - add_action('wp_enqueue_scripts', 'my-first-plugin-scripts');
defines a action for script registering so "my-first-plugin-scripts" function
will register scripts as shown above -

"wp_enqueue_script" will register jquery in that function
"wp_register_script" will register custom javascript file inside your plugin
as shown in the way above

Step-3:
Also add codes as follows -

add_shortcode("my-first-plugin-short-code", 'my-first-plugin-replace-scode');
function my-first-plugin-replace-scode(){  echo "<h2>first output</h2>";}


Code details - here "add_shortcode" will register a short code
"my-first-plugin-short-code", which when placed in any page or post code,
will be replaced by the content of the function "my-first-plugin-replace-scode()"

Step-4:
It's done.
Zip the content of your folder along with any js or css folder and install
the zipped plugin from wordpress dashboard and then activate plugin.
Place the above short code in any page or post to display your plugin content.
Read 2756 times Last modified on Thursday, 26 December 2013 15:35
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.

Latest discussions

  • No posts to display.