Create First WordPress Plugin Step by Step for Beginners

Create First WordPress Plugin Step by Step for Beginners

Today, We want to share with you Create First WordPress Plugin Step by Step for Beginners.In this post we will show you how to create plugin in wordpress step by step with example, hear for how to create plugin in wordpress with example we will give you demo and example for implement.In this post, we will learn about how to create custom plugin in wordpress from scratch with an example.

Create First WordPress Plugin Step by Step for Beginners

There are the Following The simple About Create First WordPress Plugin Step by Step for Beginners Full Information With Example and source code.

As I will cover this Post with live Working example to develop Writing a Simple WordPress Plugin, Beginner Tutorial, so the some major files and Directory structures for this example is following below.

Step-1 Create Simple Plugin Metadata.

Create file pakainfo-hello-world.phpb> as well as put below simple source code first.

<?php
/**
 * Pakainfo Hello World Plugin is the very easy WordPress plugin for step-bystep.
 * Take this as a base plugin as well as changes as per your need.
 *
 * @package Pakainfo Hello World Plugin
 * @author Pakainfo
 * @license GPL-2.0+
 * @link https://www.pakainfo.com/tag/wordpress-step-bystep/
 * @copyright 2019 Pakainfo, LLC. All rights reserved.
 *
 *            @wordpress-plugin
 *            Plugin Name: Pakainfo Hello World Plugin
 *            Plugin URI: https://www.pakainfo.com/tag/wordpress-step-bystep/
 *            Description: Pakainfo Hello World Plugin is the very easy WordPress plugin for step-bystep. Take this as a base plugin as well as changes as per your need.
 *            Version: 3.0
 *            Author: Pakainfo
 *            Author URI: https://www.pakainfo.com/
 *            Text Domain: pakainfo-hello-world
 *            Contributors: Pakainfo
 *            License: GPL-2.0+
 *            License URI: http://www.gnu.org/licenses/gpl-2.0.txt
 */

Here below fields are absolutely required as well as should be unique to your plugin:

  • Plugin Name
  • Plugin URI
  • Description
  • Version
  • Author
  • Author URI
  • Text Domain
  • Contributors
Read Also:  Add Edit And Delete Records Using jQuery Ajax PHP And MySQL

Step-2 Add submenu section

function pakainfo_add_menu() {
    add_submenu_page("options-general.php", "Pakainfo Plugin", "Pakainfo Plugin", "manage_options", "pakainfo-hello-world", "pakainfo_hello_world_page");
}
add_action("admin_menu", "pakainfo_add_menu");

Step-3 Create plugin setting page

function pakainfo_hello_world_page()
{
?>
<div class="wrap">
    <h1>
        Hello World Plugin Template By <a
            href="https://www.pakainfo.com/optimized-sharing-premium/" target="_blank">Pakainfo</a>
    </h1>
 
    <form method="post" action="options.php">
            <?php
    settings_fields("pakainfo_hello_world_config");
    do_settings_sections("pakainfo-hello-world");
    submit_button();
?>
         </form>
</div>
 
<?php
}
 
function pakainfo_hello_world_settings() {
    add_settings_section("pakainfo_hello_world_config", "", null, "pakainfo-hello-world");
    add_settings_field("pakainfo-hello-world-text", "This is sample Textbox", "pakainfo_hello_world_options", "pakainfo-hello-world", "pakainfo_hello_world_config");
    register_setting("pakainfo_hello_world_config", "pakainfo-hello-world-text");
}
add_action("admin_init", "pakainfo_hello_world_settings");
 
function pakainfo_hello_world_options() {
?>
<div class="postbox" style="width: 65%; padding: 30px;">
    <input type="text" name="pakainfo-hello-world-text"
        value="<?php
    echo stripslashes_deep(esc_attr(get_option('pakainfo-hello-world-text'))); ?>" />
    Provide any text value here for testing<br />
</div>
<?php
}

Step-4 Append Saved Textfield value to each post

add_filter('the_content', 'pakainfo_com_content');
function pakainfo_com_content($content) {
    return $content . stripslashes_deep(esc_attr(get_option('pakainfo-hello-world-text')));
}

Complete code:

Here is a complete Hello World WordPress Plugin code. Just copy it below and save to file pakainfo-hello-world.php file.

<?php
/**
 * Pakainfo Hello World Plugin is the very easy WordPress plugin for step-bystep.
 * Take this as a base plugin and changes as per your need.
 *
 * @package Pakainfo Hello World Plugin
 * @author Pakainfo
 * @license GPL-2.0+
 * @link https://www.pakainfo.com/tag/wordpress-step-bystep/
 * @copyright 2017 Pakainfo, LLC. All rights reserved.
 *
 *            @wordpress-plugin
 *            Plugin Name: Pakainfo Hello World Plugin
 *            Plugin URI: https://www.pakainfo.com/tag/wordpress-step-bystep/
 *            Description: Pakainfo Hello World Plugin is the very easy WordPress plugin for step-bystep. Take this as a base plugin and changes as per your need.
 *            Version: 3.0
 *            Author: Pakainfo
 *            Author URI: https://www.pakainfo.com/
 *            Text Domain: pakainfo-hello-world
 *            Contributors: Pakainfo
 *            License: GPL-2.0+
 *            License URI: http://www.gnu.org/licenses/gpl-2.0.txt
 */
 
/**
 * Adding Submenu under Settings Tab
 *
 * @since 1.0
 */
function pakainfo_add_menu() {
    add_submenu_page ( "options-general.php", "Pakainfo Plugin", "Pakainfo Plugin", "manage_options", "pakainfo-hello-world", "pakainfo_hello_world_page" );
}
add_action ( "admin_menu", "pakainfo_add_menu" );
 
/**
 * Setting Page Options
 * - add setting page
 * - save setting page
 *
 * @since 1.0
 */
function pakainfo_hello_world_page() {
    ?>
<div class="wrap">
    <h1>
        Hello World Plugin Template By <a
            href="https://www.pakainfo.com/" target="_blank">Pakainfo</a>
    </h1>
 
    <form method="post" action="options.php">
            <?php
    settings_fields ( "pakainfo_hello_world_config" );
    do_settings_sections ( "pakainfo-hello-world" );
    submit_button ();
    ?>
         </form>
</div>
 
<?php
}
 
/**
 * Init setting section, Init setting field and register settings page
 *
 * @since 1.0
 */
function pakainfo_hello_world_settings() {
    add_settings_section ( "pakainfo_hello_world_config", "", null, "pakainfo-hello-world" );
    add_settings_field ( "pakainfo-hello-world-text", "This is sample Textbox", "pakainfo_hello_world_options", "pakainfo-hello-world", "pakainfo_hello_world_config" );
    register_setting ( "pakainfo_hello_world_config", "pakainfo-hello-world-text" );
}
add_action ( "admin_init", "pakainfo_hello_world_settings" );
 
/**
 * Add simple textfield value to setting page
 *
 * @since 1.0
 */
function pakainfo_hello_world_options() {
    ?>
<div class="postbox" style="width: 65%; padding: 30px;">
    <input type="text" name="pakainfo-hello-world-text"
        value="<?php
    echo stripslashes_deep ( esc_attr ( get_option ( 'pakainfo-hello-world-text' ) ) );
    ?>" /> Provide any text value here for testing<br />
</div>
<?php
}
 
/**
 * Append saved textfield value to each post
 *
 * @since 1.0
 */
add_filter ( 'the_content', 'pakainfo_com_content' );
function pakainfo_com_content($content) {
    return $content . stripslashes_deep ( esc_attr ( get_option ( 'pakainfo-hello-world-text' ) ) );
}

Step-5 Create readme.txt file

Here is a sample WordPress plugin readme.txt file

Read Also:  How to Create a Wordpress Plugin in 10 Minutes Flat

=== Pakainfo Hello World Plugin ===
Contributors: Pakainfo
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8ZF6WATLYFELQ
Tags: wordpress plugin example, wordpress plugin tutorial, wordpress plugin structure, step by step wordpress plugin
Requires at least: 4.5
Tested up to: 4.7.4
Stable tag: 3.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
 
Create your fist plugin. Pakainfo Hello World Plugin is the very easy WordPress plugin for step-bystep. Take this as a base plugin as well as changes as per your need.
 
== Description ==
 
Pakainfo Hello World Plugin is the very easy WordPress plugin for step-bystep if you want to start creating fresh new plugin. Take this as a base plugin as well as changes as per your need. 
 
== Installation ==
1. Unpack the `download-package`.
2. Upload the file to the `/wp-content/plugins/` directory.
3. Activate the plugin through the `Plugins` menu in WordPress.
4. Done as well as Ready.
 
== Frequently Asked Questions ==
 
= How to add FAQ question =
* just add your FAQ questions here
 
== Screenshots ==
1. This is a text label for your first screenshot
2. Add more screenshot labels as new line
 
== Changelog ==
 
= 3.0 =
* Initial release

Web Programming Tutorials Example with Demo

Read :

Read Also:  how to create custom WordPress Plugin from scratch

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Create First WordPress Plugin Step by Step for Beginners.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

About Pakainfo

I am Jaydeep Gondaliya, a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Pakainfo →

Leave a Reply

Your email address will not be published. Required fields are marked *