Create a simple plugin to add shortcode

Create a simple plugin to add shortcode, this is a simple plugin for generating a shortcode in plugin. For this first we need to create a plugin file or files. Navigate to wp-content/plugins directory create a file with the name of shortcodeplugin.php. After creating this files open this file in file editor. Then add below lines of commented code to shortcodeplugin.php, after adding this code save this file and reload plugins page in WordPress Admin section.

<?php

/**
 * Plugin Name: Sample Shortcode plugin
 * Plugin URI: http://codingcyber.com
 * Description: A Sample shortcode plugin for adding [testshortcode].
 * Author: VIVEK KUMAR
 * Author URI: http://codingcyber.com
 * License: A "Slug" license name e.g. GPL2
 */

For making plugin working create a function with the name of create_shortcode_plugins you can use any other function name.

function create_shortcode_plugins(){
    
    $var = "Text from plugin -- add shortcode";
    return $var;
}

Then add add_shortcode action by passing two argument first one is shortcode and the other one ins function name.

add_shortcode('testshortcode', 'create_shortcode_plugins');

The Final code in shortcodeplugin.php file will look like

<?php

/**
 * Plugin Name: Sample Shortcode plugin
 * Plugin URI: http://codingcyber.com
 * Description: A Sample shortcode plugin for adding [testshortcode].
 * Author: VIVEK KUMAR
 * Author URI: http://codingcyber.com
 * License: A "Slug" license name e.g. GPL2
 */

function create_shortcode_plugins(){
    
    $var = "Text from plugin -- add shortcode";
    return $var;
}

add_shortcode('testshortcode', 'create_shortcode_plugins');

Then after activating that plugin we can call [testshortcode] in any post, page. If you have any problem let me know using comment form.

Vivek Vengala
 

Vivek Vengala is a Online Entrepreneur, Web Developer from Hyderabad India.

Click Here to Leave a Comment Below 0 comments

Leave a Reply:

x

Join My Facebook Group to Receive Coding Tutorial for Free

email-subsribe