How to Create a WordPress Plugin

Today I'm goint to show you How to Create a WordPress Plugin.

Create a WordPress plugin is very easy. The really hard stuff is to code something cool (cache plugins, database plugins...).

In our first plugin we will add some easy lines just to show how it works.

Let's get started.

1. Create the php file

Create a new my_plugin.php file. We will fill it up with the code.

You can upload it to the wp-content/plugins directory of your WordPress site.

2. Plugin Information

Now we're going to write the plugin information.

This information will show up in your Installed Plugins page.

We will set the plugin version, the plugin author, plugin description and more...

Copy and paste this code below to your my_plugin.php file and change what you want:

<?php /* Plugin Name: Remove Unwanted Code Plugin URI: https://ricard.dev Description: My First plugin. Remove unwanted code from your site. Version: 1.0 Author: quicoto Author URI: https://ricard.dev License: GPL2 */ ?>
Code language: HTML, XML (xml)

3. Add some code

Now the plugin is already working. If you upload it you will be able to activate it but it won't do anything.

I will use some lines of How to post I did so we will have all those functions in one nice plugin.

Add those lines right after the plugin information we wrote before.

<?php // Remove the WordPress version remove_action('wp_head', 'wp_generator'); // remove the WordPress.org link from the logo in the admin login function put_my_url(){ return "/"; } add_filter('login_headerurl', 'put_my_url'); remove_action('wp_head', 'start_post_rel_link'); // Removes the start link add_filter('login_errors',create_function('$a', "return 'Ops!';")); ?>
Code language: HTML, XML (xml)

Done!

The plugin is working and can be used in any WordPress site.

Let's take a look to the final code:

<?php /* Plugin Name: Remove Unwanted Code Plugin URI: https://ricard.dev Description: My First plugin. Remove unwanted code from your site. Version: 1.0 Author: quicoto Author URI: https://ricard.dev License: GPL2 */ // Remove the WordPress version remove_action('wp_head', 'wp_generator'); // remove the WordPress.org link from the logo in the admin login function put_my_url(){ return "/"; } add_filter('login_headerurl', 'put_my_url'); remove_action('wp_head', 'start_post_rel_link'); // Removes the start link add_filter('login_errors',create_function('$a', "return 'Ops!';")); ?>
Code language: HTML, XML (xml)

Questions?

Feel free to comment your questions or suggestions.

Are you working on your own plugins?

2 comments

Leave a Reply

Add <code> Some Code </code> by using this tags.

*
*