How to Use Shortcode API in a Custom or Core PHP Website

Shortcode API is one of the most effective features of WordPress. This feature has made WordPress the most popular and an easy to code Content Management System (CMS) worldwide. In this article, you will learn how to utilize the Shortcode API in a custom or core PHP website or you can say in any framework/CMS instead of WordPress.

The first step is to get the following four files from wp-includes directory:

  1. formatting.php
  2. plugin.php
  3. class-wp-hook.php
  4. shortcodes.php

After that, place all these files into the directory of your project and then include them using the following method:

In order to use a shortcode in your web page content, you need to write a function to attach the shortcode:

This heading_shortcode function will convert a plain text into a heading and change the text color.

Now, use the heading_shortcode function as a call back  function by following the statement of add_shortcode. It will be executed using/through/via do_shortcode function as follows:

To add heading in the following sample text, use [heading] shortcode:

The final step is to use the do_shortcode function as a call back function attached with the shortcode (which exists in the content):

You are done!

User Comments

2 thoughts on “How to Use Shortcode API in a Custom or Core PHP Website

    Terry Wilson says:

    Very much Informative. I love your blogs and already a follower of it. I think that when it comes to website so it’s very necessary for new business to have a custom website that perfectly show their business digitally and a complete designing solution to connect with its consumers digitally.

Leave a Reply

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

    Get in Touch