WordPress is a CMS (content management system) for bloggers, allowing you to quickly and easily set up a website. One of the great features of WordPress, which solidified its popularity, is its ability to extend. These extensions are called plugins. In this article, we will show you how to write a simple social link WordPress plugin in PHP in just 10 minutes.

Step 1: Set up the Plugin Folder and Files
The first step is to create a folder to store your plugin, we’ll use the normal WordPress convention, “wp-” and name the folder \wp-plugin. Next, we’ll create a new file for your plugin. You can do this using any text editor, such as Notepad, Sublime Text, Notepad++ or Vim on Linux. Save the file with a .php extension and give it a meaningful name, such as wp-plugin.php.

Step 2: Plugin Functionality and Meta Header
The next step is to define the functionality of your plugin. In this example below, we’ll start of by creating a simple function that adds a social link share code to the end of every blog post. Below is the code for the function. We’ll also need to add a meta header to your file. This header contains information about your plugin, such as its name, version, author, licence and description. Here is an example header, described below:

Plugin Name: My Plugin
Plugin URI: http://codesnippetsandtutorial.com/my-plugin
Description: A simple plugin that does something useful
Version: 1.0
Author: Code Snippets And Tutorials
Author URI: http://codesnippetsandtutorials.com
License: GPL2

function wp_plugin_add_social() {
    $message = '<a href="https://www.pinterest.com/pin/create/button/?url=http://example.com&description=Check%20out%20this%20cool%20website!" target="_blank" rel="noopener" > Share on Pinterest </a>';
 return $message;

Step 3: Hook the Function to WordPress
The next step is to hook our function to WordPress. The architecture for WordPress CMS is hook based, which allows you to run your plugin code at specific places in the code execution process. These hooks are located throughout the entire CMS. In this example, we’ll hook our newly created method to the “the_content” hook, which runs after the main content of a blog post. Here is the code to hook our function:

add_filter( 'the_content', 'wp_plugin_add_social' );

This code tells WordPress CMS to exectute the “wp_plugin_add_social” function, when “the_content” hook is triggered.

Step 4: Test the Plugin
The final step is to test our newly created plugin. To do this, we need to install the plugin. Let’s go ahead and upload our plugin file to the “wp-content/plugins” directory of our WordPress install. Once the folder and file are uploaded, we can activate the plugin from the WordPress dashboard. You can read more about activating a plugin here.

After activating the plugin, create a new blog post and publish it. You should see our custom social link, added to the end of the post.

In just 10 minutes, we have created a simple WordPress plugin that adds custom social media sharing functionality to our website or blog.