what is "shortcode" and How to Create a Shortcode in WordPress ?

Collapse

Unconfigured Ad Widget

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Rachel S
    Senior Member
    • Apr 2022
    • 113

    what is "shortcode" and How to Create a Shortcode in WordPress ?

    Hello Everyone
    I'm eager to learn how one can create these shortcodes effectively within the WordPress ecosystem. Any help highly appreciate.
  • Ryaan J.
    Senior Member
    • Apr 2022
    • 106

    #2
    What is Shortcode?

    WordPress shortcodes behave as shortcuts that make it simple to embed components into a post or page quickly. These typically consist of one line of code enclosed in square brackets, like [exampleofshortcode].

    Users may now easily add features to their posts and websites, such as Facebook's "Like" button or Google Maps.

    WordPress has six default shortcodes:
    • Caption: Wraps captions around content
    • Gallery: shows images gallery
    • audio: embeds and plays audio files
    • Video: embeds and plays video files
    • Playlist: displays a collection of video or audio files
    • embed: wraps embedded items

    How to create Shortcode in WordPress?

    1. Log into your CPanel account.

    2. Scroll down to the Files and choose File Manager.



    3. Inside the public_html directory, choose the wp-content folder.


    4. Select the themes folder and navigate to your current theme. In our example, this will be twentytwentyone.






    5. On the top-left side of the page, click on the +File option.

    6. Create a new file create_shortcode.php file.




    7. Now include create_shortcode.php file in function.php. For that, right-click on the file and click Edit.

    8. Add the following code to the function.php file.
    • include('create_shortcode.php');
    9. Now, Right-click on the create_shortcode.php file and choose Edit.

    10. Add the below code into the create_shortcode.php file.

    <?php
    function subscribe_link(){
    return 'Follow us on <a rel="nofollow" href="https://twitter.com/abc?s=20">Twitter</a>';
    }
    add_shortcode('subscribe', 'subscribe_link');
    ?>





    You can test your shortcode by following the below steps:
    1. Log into your WordPress Dashboard.
    2. Navigate to post > Add New.
    3. You can easily enter the [subscribe] tag into the post using the WordPress Block Editor:
    4. Click on Preview > Preview in the new tab.

















    Comment

    Working...
    X