How To Create Custom Shortcode In WordPress

In This article I will show you How to create shortcode in WordPress.

There are 2 methods to create Shortcode.

Method 1:

In this method we are adding code in add_shortcode action it self. We don’t need to initialize of define any function for that.

add_shortcode('custom_test_shortcode', function () {
  echo "Custom Test Shortcode";
});

Method 2:

In this method we are going to initialize the function and then we are going to use that function into the add_shortcode action.

add_shortcode('test_shortcode', 'test_shortcode');
function test_shortcode() {
  echo "Test Shortcode";
}

In given example I have created test_shortcode() function.

In which I have just added simple echo text you can add any code within that function which you want to display on your page.

Then you need to pass your function name into the add_shortcode action.

Thank You.

Submit a Comment

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

Subscribe

Select Categories