How to Write a Simple WordPress Plugin

0
2282

When you have a good WordPress blog and plugins are installed from the plugin’s library,  you can create your own simple WordPress plugin. How you want to customize it depends on your needs. Here’s an article outlining the steps necessary on How to Write a Simple WordPress Plugin!

The main factor of a WP plugin are the 2 functions listed below (known as “hooks“)
add_action($tag,$function);
add_filter($tag,$function);

The definition of the two important functions are:
Add_action: Invoke a function in one or more locations in WP enforcement process.
Add_filter: Used for filtering data or replacing content and returning results for web browser display.
You should refer to the WordPress Codex for a more detailed explanation.

Information about Plugin

Showing your text when the plugin is activated in the WordPress dashboard.

First, you need to create a file webcome-to-webmastersun.php and add the code to it.

<?php
/*
Plugin Name: Welcome to Webmaster Sun
Plugin URI: https://www.webmastersun.com
Description: Say "Welcome to Webmaster Sun" at wherever you want
Version: 1.0
Author: Webmaster Sun
Author URI: https://www.webmastersun.com
License: GPL
*/
?>

Copy this file into wordpress > wp-content > plugins and go to Admin > Plugins and see what is showing.

simple_wordpress_plugin_1

How it works

The plugin will show “Welcome to Webmaster Sun, A great forum for discussing about SEO, Web Development and Internet Marketing Online!!!” on any page templates that you want.

Activate plugin and add this code to the page templates you want them to appear:

<?php
if(function_exists('welcome_to_webmastersun')) {
welcome_to_webmastersun();
}
?>

Ok, now let’s go with the detail.

Complete code:

<?php
/*
Plugin Name: Welcome to Webmaster Sun
Plugin URI: https://www.webmastersun.com
Description: Say "Welcome to Webmaster Sun" at wherever you want
Version: 1.0
Author: Webmaster Sun
Author URI: https://www.webmastersun.com
License: GPL
*/
/* This calls welcome_to_webmastersun() function when this function called in your wordpress
file.*/
function welcome_to_webmastersun()
{
echo "Welcome to Webmaster Sun, A great forum for discussing about SEO, Web Development and
Internet Marketing Online!!!";
}
?>

Explanation: When your pages are being shown then the function welcome_to_webmastersun() will be called and return its value.

This is the result we will get:

simple_wordpress_plugin_pic

You can customize this plugin to do anything. For example, replace strings in content, remove unexpected characters or make titles capitalized…etc with add_action and add_filter function of plugin.

Remember to activate the plugin to see your result.

Good luck!

LEAVE A REPLY

Please enter your comment!
Please enter your name here