If you already have some coding knowledge, you may create your own custom shortcodes. This gives you complete control over the see and functionality of your site.

Let’s see at how to create custom WordPress shortcode. In this article, we shall be adding social media links to a post as our example.

Step 1: Create a New Folder

First step go to your file manager->XAMPP->htdocs->WordPress->wp-content->Plugins and create a new folder ->follow_us.

Step 2: Save the PHP File

open your text editor and save the .php file in wp-content->plugin->follow_us.

Step 3: Create a Shortcode code

Next, you’ll need to create the function of the shortcode, instructing it what to do. Choose the View/Edit option again for your follow_us.php file.

To add handling attributes, you need to open the follow_us.php file and use the following code:

function webart_follow_us_link($atts,$content = null) {
    $default = array(
        'link' => '#',
    );
    $a = shortcode_atts($default, $atts);
    $content = do_shortcode($content);
    return 'Follow us on <a href="'.$a['link'].'"style="color: blue">'.$content.'</a>';
}
add_shortcode('follow_us','webart_follow_us_link');

Step 4: Activate the follow us Plugin

Search the follow us plugin and click the Activate button to make it your active Plugin.

Step 5: Add the Shortcode to the Website

You can now test your initial code as a shortcode on your WordPress site. Using the WordPress Block Editor, you can insert the following tag directly into the post:

[follow_us link=”https://www.facebook.com/”]Facebook[/follow_us]

Step 6: Display  the Shortcode to your Website

It will display the following content to your website visitors:

Conclusion:

It’s very easy to add extra functionality to your WordPress website with shortcodes. You can use them to customize your existing content and add interactive features, like contact forms, image galleries, or subscription links.

Similar Posts