Creating Wordpress Plugin
Step 1 : \wp-content\plugins
Step 2 : create a folder "myplugin"
Step 3 : create a php file "my_plugin.php"
Step 4 : add following code into the file
<code>
<?php
/*
Plugin Name: Hi Plugin
Plugin URI: http://www.example.com
Description: This test Plugin Created by me.
Author: RK
Version: 1.0
Author URI: http://www.example2.com
*/
//add_action('admin_notices','hello_world'); // display notice bar on the admin panel
header('content-type: text/plain');
//add_filter('admin_head','hello_world');
add_filter('the_content','hello_world');
add_action('init','hello_add_js_to_doc_head'); // function initialize the javaScript.
//add_action('get_header','hello_world');
//add_action('admin_footer','hello_world'); // display content on footer
// function to include external js file
function hello_add_js_to_doc_head(){
$src=plugins_url('hello.js',__FILE__); // locate the file path
wp_register_script('hello',$src); // include the file
wp_enqueue_script('hello'); // execute the js file for onload initialization.
}
// function display content and a twitter link -- $input means actual posted content
function hello_world($input){
$chos = hello_get_me();
return $input."<p id='me'> $chos</p>";
}
// function to display a label on the content as Follow me on Twitter.
function hello_get_me(){
?>
<a href="http://www.example.com" target="_blank" onclick="myalertbx()">Follow Me Twitter</a>
<?php
}
?>
</code>
Step 5 : create an another file "hello.js"
Step 6 : add following code into the file
<code>
(function() {
var s = document.createElement('SCRIPT'), s1 = document.
getElementsByTagName('SCRIPT')[0];
s.type = 'text/javascript';
s.async = true;
s.src = 'http://widgets.digg.com/buttons.js';
s1.parentNode.insertBefore(s, s1);
//alert("hi there");
})();
function myalertbx(){
alert("Hello you Clickme : Go to my Twitter Page");
}
</code>
Step 7 : Execute in wordpress plugin menu
Step 8 : Active the plugin
Step 9 : Enjoy
by Ravi Arsid.
No comments:
Post a Comment