{"id":2650,"date":"2026-10-01T17:18:42","date_gmt":"2026-10-01T11:48:42","guid":{"rendered":"https:\/\/ehostpiya.in\/blog\/?p=2650"},"modified":"2026-10-01T17:18:59","modified_gmt":"2026-10-01T11:48:59","slug":"how-to-create-a-wordpress-shortcode","status":"publish","type":"post","link":"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/","title":{"rendered":"How to Create a WordPress Shortcode?"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_88 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#How_to_Create_a_WordPress_Shortcode\" >How to Create a WordPress Shortcode<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#What_Is_a_WordPress_Shortcode\" >What Is a WordPress Shortcode?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Why_Use_Shortcodes\" >Why Use Shortcodes?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Before_Creating_a_Shortcode\" >Before Creating a Shortcode<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Method_1_Create_a_Simple_WordPress_Shortcode\" >Method 1: Create a Simple WordPress Shortcode<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Understanding_add_shortcode\" >Understanding add_shortcode()<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Shortcode_Name\" >Shortcode Name<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Callback_Function\" >Callback Function<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Important_Return_Instead_of_Echo\" >Important: Return Instead of Echo<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Create_a_Shortcode_That_Outputs_HTML\" >Create a Shortcode That Outputs HTML<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Creating_a_Shortcode_for_a_Button\" >Creating a Shortcode for a Button<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#How_to_Add_Attributes_to_a_Shortcode\" >How to Add Attributes to a Shortcode<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#What_Is_shortcode_atts\" >What Is shortcode_atts()?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Always_Escape_Shortcode_Output\" >Always Escape Shortcode Output<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Creating_a_Shortcode_With_Content\" >Creating a Shortcode With Content<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Using_Shortcode_Attributes_With_Content\" >Using Shortcode Attributes With Content<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Using_Shortcodes_Inside_Other_Shortcodes\" >Using Shortcodes Inside Other Shortcodes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Creating_a_Shortcode_That_Displays_the_Current_Year\" >Creating a Shortcode That Displays the Current Year<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Creating_a_Shortcode_With_a_Custom_CSS_Class\" >Creating a Shortcode With a Custom CSS Class<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Where_Should_You_Add_Custom_Shortcode_Code\" >Where Should You Add Custom Shortcode Code?<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#1_Custom_Plugin\" >1. Custom Plugin<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-22\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#2_Child_Theme_functionsphp\" >2. Child Theme functions.php<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-23\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#3_Code_Snippets_Plugin\" >3. Code Snippets Plugin<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-24\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#How_to_Use_a_Shortcode_in_WordPress\" >How to Use a Shortcode in WordPress<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-25\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Can_Shortcodes_Be_Used_in_Widgets\" >Can Shortcodes Be Used in Widgets?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-26\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Can_Shortcodes_Be_Used_in_PHP_Templates\" >Can Shortcodes Be Used in PHP Templates?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-27\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Adding_a_Shortcode_to_a_Custom_Plugin\" >Adding a Shortcode to a Custom Plugin<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-28\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Common_Shortcode_Mistakes\" >Common Shortcode Mistakes<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-29\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#1_Using_echo_Instead_of_return\" >1. Using echo Instead of return<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-30\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#2_Using_a_Generic_Shortcode_Name\" >2. Using a Generic Shortcode Name<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-31\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#3_Forgetting_to_Escape_Output\" >3. Forgetting to Escape Output<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-32\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#4_Adding_Too_Much_Functionality_to_One_Shortcode\" >4. Adding Too Much Functionality to One Shortcode<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-33\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#5_Editing_the_Parent_Theme\" >5. Editing the Parent Theme<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-34\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Shortcode_Security_Best_Practices\" >Shortcode Security Best Practices<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-35\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Validate_input\" >Validate input<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-36\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Escape_output\" >Escape output<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-37\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Use_nonces_when_handling_actions\" >Use nonces when handling actions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-38\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Check_user_capabilities\" >Check user capabilities<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-39\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Avoid_executing_arbitrary_PHP\" >Avoid executing arbitrary PHP<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-40\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Shortcode_vs_Custom_Block\" >Shortcode vs Custom Block<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-41\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Shortcode_vs_Plugin\" >Shortcode vs Plugin<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-42\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Example_Complete_Custom_Shortcode\" >Example: Complete Custom Shortcode<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-43\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Best_Practices_for_WordPress_Shortcodes\" >Best Practices for WordPress Shortcodes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-44\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Troubleshooting_WordPress_Shortcodes\" >Troubleshooting WordPress Shortcodes<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-45\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Shortcode_Appears_as_Plain_Text\" >Shortcode Appears as Plain Text<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-46\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Shortcode_Produces_a_Blank_Area\" >Shortcode Produces a Blank Area<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-47\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Shortcode_Causes_a_PHP_Error\" >Shortcode Causes a PHP Error<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-48\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Shortcode_Conflicts_With_Another_Plugin\" >Shortcode Conflicts With Another Plugin<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-49\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Frequently_Asked_Questions\" >Frequently Asked Questions<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-50\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#What_is_a_WordPress_shortcode\" >What is a WordPress shortcode?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-51\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Where_should_I_add_shortcode_PHP_code\" >Where should I add shortcode PHP code?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-52\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Can_a_shortcode_accept_parameters\" >Can a shortcode accept parameters?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-53\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Can_a_shortcode_contain_content\" >Can a shortcode contain content?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-54\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Should_a_shortcode_echo_or_return_content\" >Should a shortcode echo or return content?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-55\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Can_shortcodes_be_used_in_PHP_templates\" >Can shortcodes be used in PHP templates?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-56\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Are_shortcodes_still_useful_in_WordPress\" >Are shortcodes still useful in WordPress?<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-57\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#Final_Thoughts\" >Final Thoughts<\/a><\/li><\/ul><\/nav><\/div>\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Create_a_WordPress_Shortcode\"><\/span>How to Create a WordPress Shortcode<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">WordPress shortcodes provide a simple way to insert dynamic content into posts, pages, widgets, and other areas of a website without repeatedly writing complex HTML or PHP code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A shortcode looks like a small piece of text enclosed in square brackets, such as:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;my_shortcode]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">When WordPress processes the page, it detects the shortcode and replaces it with the content generated by the associated PHP function.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this guide, you&#8217;ll learn how to create a custom WordPress shortcode, pass attributes to it, accept content between shortcode tags, and follow security and performance best practices.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_Is_a_WordPress_Shortcode\"><\/span>What Is a WordPress Shortcode?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A WordPress shortcode is a special tag that allows users to execute predefined functionality inside WordPress content.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;contact_box]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">could display:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">Need help? Contact our support team today.<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">Instead of manually entering the same HTML every time, you can simply insert the shortcode wherever you want the content to appear.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">WordPress includes several built-in shortcodes, while developers can create their own using PHP.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Why_Use_Shortcodes\"><\/span>Why Use Shortcodes?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Shortcodes are useful when you want to reuse specific functionality throughout a website.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Common applications include:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Call-to-action boxes<\/li>\n\n\n\n<li>Buttons<\/li>\n\n\n\n<li>Contact information<\/li>\n\n\n\n<li>Product displays<\/li>\n\n\n\n<li>Pricing tables<\/li>\n\n\n\n<li>Custom notices<\/li>\n\n\n\n<li>Download links<\/li>\n\n\n\n<li>Dynamic content<\/li>\n\n\n\n<li>Custom forms<\/li>\n\n\n\n<li>Frequently used HTML layouts<\/li>\n\n\n\n<li>Information pulled from WordPress data<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">For example, instead of repeatedly adding a complex button structure, you could use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;hosting_button]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This makes content easier to manage and reuse.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Before_Creating_a_Shortcode\"><\/span>Before Creating a Shortcode<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before adding custom PHP code to WordPress, create a backup of your website.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is also preferable to test custom code on a staging website before applying it to a production site.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There are several places where you can add shortcode code:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>A custom plugin<\/li>\n\n\n\n<li>A child theme&#8217;s <code>functions.php<\/code><\/li>\n\n\n\n<li>A code snippets plugin<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">For functionality that should remain available even when the theme changes, a <strong>custom plugin<\/strong> is generally the better choice.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Method_1_Create_a_Simple_WordPress_Shortcode\"><\/span>Method 1: Create a Simple WordPress Shortcode<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s create a basic shortcode called:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;welcome_message]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Add the following PHP code to a custom plugin or your child theme&#8217;s <code>functions.php<\/code> file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function ehostpiya_welcome_message() {\n    return 'Welcome to our website!';\n}\n\nadd_shortcode('welcome_message', 'ehostpiya_welcome_message');<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can now add this shortcode to a WordPress post or page:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;welcome_message]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">WordPress will execute the function and display:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Welcome to our website!<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Understanding_add_shortcode\"><\/span>Understanding <code>add_shortcode()<\/code><span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">The following line registers the shortcode:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>add_shortcode('welcome_message', 'ehostpiya_welcome_message');<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">It contains two important parameters:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>add_shortcode('shortcode_name', 'callback_function');<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Shortcode_Name\"><\/span>Shortcode Name<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This is the name users enter inside square brackets:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;welcome_message]<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Callback_Function\"><\/span>Callback Function<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This is the PHP function WordPress calls when it finds the shortcode:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ehostpiya_welcome_message<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Important_Return_Instead_of_Echo\"><\/span>Important: Return Instead of Echo<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">One of the most important rules when creating WordPress shortcodes is to <strong>return the output rather than echo it<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Correct:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function ehostpiya_message() {\n    return 'Hello from WordPress!';\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Avoid:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function ehostpiya_message() {\n    echo 'Hello from WordPress!';\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Shortcode callbacks are expected to return their generated content.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Returning the output allows WordPress to place the shortcode result correctly within the page content.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Create_a_Shortcode_That_Outputs_HTML\"><\/span>Create a Shortcode That Outputs HTML<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Shortcodes become more useful when they generate HTML.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function ehostpiya_notice() {\n    return '&lt;div class=\"custom-notice\"&gt;This is a custom WordPress notice.&lt;\/div&gt;';\n}\n\nadd_shortcode('notice', 'ehostpiya_notice');<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Use it inside your content:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;notice]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The shortcode will generate:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;div class=\"custom-notice\"&gt;This is a custom WordPress notice.&lt;\/div&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can then style the <code>.custom-notice<\/code> class with CSS.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Creating_a_Shortcode_for_a_Button\"><\/span>Creating a Shortcode for a Button<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">A common shortcode application is creating reusable buttons.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function ehostpiya_button() {\n    return '&lt;a href=\"https:\/\/example.com\" class=\"custom-button\"&gt;Learn More&lt;\/a&gt;';\n}\n\nadd_shortcode('learn_more', 'ehostpiya_button');<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;learn_more]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The generated HTML will be:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;a href=\"https:\/\/example.com\" class=\"custom-button\"&gt;Learn More&lt;\/a&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You could then add CSS:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.custom-button {\n    display: inline-block;\n    padding: 10px 20px;\n    text-decoration: none;\n    border-radius: 5px;\n}<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Add_Attributes_to_a_Shortcode\"><\/span>How to Add Attributes to a Shortcode<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Shortcodes can accept attributes, allowing users to customize the output.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;button text=\"Learn More\" url=\"https:\/\/example.com\"]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Create the shortcode with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function ehostpiya_button_shortcode($atts) {\n\n    $atts = shortcode_atts(\n        array(\n            'text' =&gt; 'Click Here',\n            'url'  =&gt; '#',\n        ),\n        $atts,\n        'button'\n    );\n\n    return '&lt;a href=\"' . esc_url($atts&#91;'url']) . '\" class=\"custom-button\"&gt;' .\n        esc_html($atts&#91;'text']) .\n        '&lt;\/a&gt;';\n}\n\nadd_shortcode('button', 'ehostpiya_button_shortcode');<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Now you can customize the button without changing the PHP code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;button text=\"Get Started\" url=\"https:\/\/example.com\"]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Or:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;button text=\"View Plans\" url=\"https:\/\/example.com\/pricing\"]<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_Is_shortcode_atts\"><\/span>What Is <code>shortcode_atts()<\/code>?<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>shortcode_atts()<\/code> function provides default values for shortcode attributes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$atts = shortcode_atts(\n    array(\n        'text' =&gt; 'Click Here',\n        'url'  =&gt; '#',\n    ),\n    $atts,\n    'button'\n);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If a user writes:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;button]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">WordPress will use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>text = Click Here\nurl = #<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the user provides attributes, those values override the defaults.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Always_Escape_Shortcode_Output\"><\/span>Always Escape Shortcode Output<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">When shortcode attributes are used to generate HTML, user-supplied values should be properly escaped.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For URLs, use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>esc_url()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For plain text, use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>esc_html()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For HTML attributes, use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>esc_attr()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>return '&lt;a href=\"' . esc_url($atts&#91;'url']) . '\"&gt;' .\n    esc_html($atts&#91;'text']) .\n    '&lt;\/a&gt;';<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Escaping helps prevent malicious or malformed input from being inserted into your website&#8217;s output.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Creating_a_Shortcode_With_Content\"><\/span>Creating a Shortcode With Content<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Shortcodes can also contain content between an opening and closing tag.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;box]\nThis is the content inside the box.\n&#91;\/box]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Create the shortcode like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function ehostpiya_box_shortcode($atts, $content = null) {\n\n    return '&lt;div class=\"custom-box\"&gt;' .\n        do_shortcode($content) .\n        '&lt;\/div&gt;';\n}\n\nadd_shortcode('box', 'ehostpiya_box_shortcode');<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>$content<\/code> parameter contains everything between the opening and closing shortcode tags.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_Shortcode_Attributes_With_Content\"><\/span>Using Shortcode Attributes With Content<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">You can combine attributes and enclosed content.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;box title=\"Important Notice\"]\nRemember to back up your WordPress website regularly.\n&#91;\/box]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">PHP:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function ehostpiya_box_shortcode($atts, $content = null) {\n\n    $atts = shortcode_atts(\n        array(\n            'title' =&gt; 'Notice',\n        ),\n        $atts,\n        'box'\n    );\n\n    return '&lt;div class=\"custom-box\"&gt;\n        &lt;h3&gt;' . esc_html($atts&#91;'title']) . '&lt;\/h3&gt;\n        &lt;div&gt;' . do_shortcode($content) . '&lt;\/div&gt;\n    &lt;\/div&gt;';\n}\n\nadd_shortcode('box', 'ehostpiya_box_shortcode');<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This provides a flexible reusable content box.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_Shortcodes_Inside_Other_Shortcodes\"><\/span>Using Shortcodes Inside Other Shortcodes<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">If your shortcode contains another shortcode, you can use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>do_shortcode($content);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function ehostpiya_wrapper($atts, $content = null) {\n    return '&lt;div class=\"wrapper\"&gt;' . do_shortcode($content) . '&lt;\/div&gt;';\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;wrapper]\n&#91;button text=\"Get Started\" url=\"https:\/\/example.com\"]\n&#91;\/wrapper]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">WordPress processes the nested shortcode inside the wrapper.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Creating_a_Shortcode_That_Displays_the_Current_Year\"><\/span>Creating a Shortcode That Displays the Current Year<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">A useful example is a dynamic copyright year.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function ehostpiya_current_year() {\n    return date('Y');\n}\n\nadd_shortcode('current_year', 'ehostpiya_current_year');<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can then use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u00a9 &#91;current_year] Your Company<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The shortcode automatically displays the current year.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A WordPress-specific alternative is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function ehostpiya_current_year() {\n    return wp_date('Y');\n}\n\nadd_shortcode('current_year', 'ehostpiya_current_year');<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Using WordPress&#8217;s date functions is preferable because they respect the site&#8217;s configured timezone.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Creating_a_Shortcode_With_a_Custom_CSS_Class\"><\/span>Creating a Shortcode With a Custom CSS Class<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">You can generate markup with a dedicated class:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function ehostpiya_info_shortcode($atts, $content = null) {\n\n    return '&lt;div class=\"ehostpiya-info\"&gt;' .\n        do_shortcode($content) .\n        '&lt;\/div&gt;';\n}\n\nadd_shortcode('info', 'ehostpiya_info_shortcode');<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then add CSS:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.ehostpiya-info {\n    padding: 20px;\n    border: 1px solid #ddd;\n    border-radius: 8px;\n    margin: 20px 0;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;info]\nYour information goes here.\n&#91;\/info]<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Where_Should_You_Add_Custom_Shortcode_Code\"><\/span>Where Should You Add Custom Shortcode Code?<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">There are several options.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Custom_Plugin\"><\/span>1. Custom Plugin<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A custom plugin is often the best solution for site functionality.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wp-content\/\n\u2514\u2500\u2500 plugins\/\n    \u2514\u2500\u2500 custom-shortcodes\/\n        \u2514\u2500\u2500 custom-shortcodes.php<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The plugin file could contain:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\/**\n * Plugin Name: Custom Shortcodes\n * Description: Adds custom shortcodes to WordPress.\n * Version: 1.0.0\n *\/\n\nfunction ehostpiya_message_shortcode() {\n    return 'Welcome to our website!';\n}\n\nadd_shortcode('welcome_message', 'ehostpiya_message_shortcode');<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Activate the plugin from the WordPress admin dashboard.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The shortcode will then be available throughout the website.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Child_Theme_functionsphp\"><\/span>2. Child Theme <code>functions.php<\/code><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You can also add the shortcode to:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/wp-content\/themes\/your-child-theme\/functions.php<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This approach can work well for functionality specifically tied to the child theme.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, if you change themes, the shortcode functionality will no longer be loaded.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Code_Snippets_Plugin\"><\/span>3. Code Snippets Plugin<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Another convenient option is using a reputable code snippets plugin.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This allows you to add PHP without directly editing theme files.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It can be especially useful when you do not want to manually modify <code>functions.php<\/code>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Use_a_Shortcode_in_WordPress\"><\/span>How to Use a Shortcode in WordPress<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">After registering the shortcode, you can insert it into compatible WordPress content areas.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;welcome_message]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Depending on the WordPress editor and the location, you can use a <strong>Shortcode block<\/strong> in the block editor.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can also use shortcodes in classic editor content.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Some themes and plugins provide additional shortcode-compatible areas.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Can_Shortcodes_Be_Used_in_Widgets\"><\/span>Can Shortcodes Be Used in Widgets?<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Shortcode support depends on the widget or block being used.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In WordPress environments where shortcode processing is supported, you can place something such as:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;welcome_message]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">inside the appropriate content area.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If a shortcode appears as plain text instead of being processed, check whether that particular widget, block, theme, or plugin applies shortcode processing.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Can_Shortcodes_Be_Used_in_PHP_Templates\"><\/span>Can Shortcodes Be Used in PHP Templates?<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Yes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you need to execute a shortcode directly from a PHP template, use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo do_shortcode('&#91;welcome_message]');<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For a shortcode with attributes:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo do_shortcode('&#91;button text=\"Learn More\" url=\"https:\/\/example.com\"]');<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Use this approach carefully, especially when the shortcode contains user-controlled values.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Adding_a_Shortcode_to_a_Custom_Plugin\"><\/span>Adding a Shortcode to a Custom Plugin<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">For larger websites, it is useful to keep custom shortcodes organized inside a plugin.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>custom-shortcodes\/\n\u251c\u2500\u2500 custom-shortcodes.php\n\u251c\u2500\u2500 includes\/\n\u2502   \u2514\u2500\u2500 shortcodes.php\n\u251c\u2500\u2500 assets\/\n\u2502   \u251c\u2500\u2500 css\/\n\u2502   \u2502   \u2514\u2500\u2500 shortcodes.css\n\u2502   \u2514\u2500\u2500 js\/\n\u2502       \u2514\u2500\u2500 shortcodes.js<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The main plugin file can load the shortcode functionality.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This structure becomes easier to maintain as the number of shortcodes increases.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Common_Shortcode_Mistakes\"><\/span>Common Shortcode Mistakes<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Using_echo_Instead_of_return\"><\/span>1. Using <code>echo<\/code> Instead of <code>return<\/code><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Incorrect:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function my_shortcode() {\n    echo 'Hello';\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Correct:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function my_shortcode() {\n    return 'Hello';\n}<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Using_a_Generic_Shortcode_Name\"><\/span>2. Using a Generic Shortcode Name<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Avoid extremely generic names such as:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;button]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">if another plugin may already register the same shortcode.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A more unique naming convention can reduce conflicts:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;ehostpiya_button]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Prefixing functions and shortcode names is a useful practice for custom development.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Forgetting_to_Escape_Output\"><\/span>3. Forgetting to Escape Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Avoid directly inserting untrusted values into HTML.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Instead of:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>return '&lt;a href=\"' . $atts&#91;'url'] . '\"&gt;' . $atts&#91;'text'] . '&lt;\/a&gt;';<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>return '&lt;a href=\"' . esc_url($atts&#91;'url']) . '\"&gt;' .\n    esc_html($atts&#91;'text']) .\n    '&lt;\/a&gt;';<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_Adding_Too_Much_Functionality_to_One_Shortcode\"><\/span>4. Adding Too Much Functionality to One Shortcode<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A shortcode should ideally perform one clear task.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Instead of creating one shortcode responsible for an entire complex application, consider separating functionality into appropriate functions, classes, plugins, or blocks.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5_Editing_the_Parent_Theme\"><\/span>5. Editing the Parent Theme<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Avoid putting custom shortcode functionality directly into a parent theme&#8217;s <code>functions.php<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Theme updates can overwrite your modifications.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A child theme or custom plugin is safer.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Shortcode_Security_Best_Practices\"><\/span>Shortcode Security Best Practices<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">When developing custom shortcodes:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Validate_input\"><\/span>Validate input<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Make sure shortcode attributes contain appropriate values.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Escape_output\"><\/span>Escape output<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Use the appropriate WordPress escaping function before displaying dynamic data.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Use_nonces_when_handling_actions\"><\/span>Use nonces when handling actions<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If a shortcode creates forms or performs administrative actions, implement WordPress nonce protection where appropriate.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Check_user_capabilities\"><\/span>Check user capabilities<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If the shortcode exposes privileged functionality, verify the current user&#8217;s permissions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Avoid_executing_arbitrary_PHP\"><\/span>Avoid executing arbitrary PHP<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Never design a shortcode that accepts PHP code from normal website content and executes it.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Shortcode_vs_Custom_Block\"><\/span>Shortcode vs Custom Block<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Shortcodes remain useful, but modern WordPress development increasingly uses blocks.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A shortcode may be appropriate when:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You need a simple reusable content element.<\/li>\n\n\n\n<li>You are maintaining an existing shortcode-based website.<\/li>\n\n\n\n<li>You need a quick dynamic output mechanism.<\/li>\n\n\n\n<li>The content is primarily text-based.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">A custom block may be preferable when:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Users need a visual editing interface.<\/li>\n\n\n\n<li>The component has many configurable options.<\/li>\n\n\n\n<li>You want a richer editing experience.<\/li>\n\n\n\n<li>You are developing a modern block-based WordPress site.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Shortcode_vs_Plugin\"><\/span>Shortcode vs Plugin<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">A shortcode is a piece of functionality.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A plugin is a package that can contain one or many features, including shortcodes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Plugin\n \u251c\u2500\u2500 Shortcode\n \u251c\u2500\u2500 Settings\n \u251c\u2500\u2500 Admin interface\n \u251c\u2500\u2500 CSS\n \u2514\u2500\u2500 JavaScript<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Therefore, a custom plugin can be an excellent place to store important shortcode functionality.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_Complete_Custom_Shortcode\"><\/span>Example: Complete Custom Shortcode<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Here is a practical shortcode that creates a reusable hosting promotion box:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function ehostpiya_hosting_box($atts) {\n\n    $atts = shortcode_atts(\n        array(\n            'title' =&gt; 'Web Hosting',\n            'text'  =&gt; 'Fast and reliable hosting for your website.',\n            'url'   =&gt; '#',\n        ),\n        $atts,\n        'hosting_box'\n    );\n\n    return '&lt;div class=\"hosting-box\"&gt;\n        &lt;h3&gt;' . esc_html($atts&#91;'title']) . '&lt;\/h3&gt;\n        &lt;p&gt;' . esc_html($atts&#91;'text']) . '&lt;\/p&gt;\n        &lt;a href=\"' . esc_url($atts&#91;'url']) . '\" class=\"hosting-button\"&gt;\n            Get Started\n        &lt;\/a&gt;\n    &lt;\/div&gt;';\n}\n\nadd_shortcode('hosting_box', 'ehostpiya_hosting_box');<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You can use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;hosting_box\ntitle=\"Premium Web Hosting\"\ntext=\"Launch your website with fast and reliable hosting.\"\nurl=\"https:\/\/example.com\"]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This approach lets you reuse the same component with different content.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Best_Practices_for_WordPress_Shortcodes\"><\/span>Best Practices for WordPress Shortcodes<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Follow these practices when creating custom shortcodes:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Use unique shortcode names.<\/li>\n\n\n\n<li>Prefix custom PHP functions to prevent naming conflicts.<\/li>\n\n\n\n<li>Return shortcode output instead of echoing it.<\/li>\n\n\n\n<li>Use <code>shortcode_atts()<\/code> for default attributes.<\/li>\n\n\n\n<li>Escape dynamic output.<\/li>\n\n\n\n<li>Keep shortcodes focused on one purpose.<\/li>\n\n\n\n<li>Store important functionality in a custom plugin.<\/li>\n\n\n\n<li>Test shortcodes on desktop and mobile layouts.<\/li>\n\n\n\n<li>Check compatibility with your theme and plugins.<\/li>\n\n\n\n<li>Avoid unnecessary database queries.<\/li>\n\n\n\n<li>Keep generated HTML semantic and accessible.<\/li>\n\n\n\n<li>Document custom shortcode attributes.<\/li>\n\n\n\n<li>Test empty or invalid attribute values.<\/li>\n\n\n\n<li>Use proper permission and security checks when needed.<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Troubleshooting_WordPress_Shortcodes\"><\/span>Troubleshooting WordPress Shortcodes<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Shortcode_Appears_as_Plain_Text\"><\/span>Shortcode Appears as Plain Text<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If you see:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;my_shortcode]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">instead of the expected output, check:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Whether the shortcode was registered.<\/li>\n\n\n\n<li>Whether the PHP code contains a syntax error.<\/li>\n\n\n\n<li>Whether the plugin is activated.<\/li>\n\n\n\n<li>Whether the shortcode name is correct.<\/li>\n\n\n\n<li>Whether the location supports shortcode processing.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Shortcode_Produces_a_Blank_Area\"><\/span>Shortcode Produces a Blank Area<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Check the callback function.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Make sure it returns something:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>return 'Content';<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">rather than only executing an action or producing no output.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Shortcode_Causes_a_PHP_Error\"><\/span>Shortcode Causes a PHP Error<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Review the PHP syntax and WordPress debug log.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For temporary development debugging, you can enable WordPress debugging in <code>wp-config.php<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>define('WP_DEBUG', true);\ndefine('WP_DEBUG_LOG', true);\ndefine('WP_DEBUG_DISPLAY', false);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Avoid displaying PHP errors publicly on a production website.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Shortcode_Conflicts_With_Another_Plugin\"><\/span>Shortcode Conflicts With Another Plugin<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Two plugins can potentially register the same shortcode name.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use a unique naming convention, such as:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;ehostpiya_button]<\/code><\/pre>\n\n\n<p>[ehostpiya_notice]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">[ehostpiya_hosting_box]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This reduces the possibility of conflicts.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Frequently_Asked_Questions\"><\/span>Frequently Asked Questions<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_is_a_WordPress_shortcode\"><\/span>What is a WordPress shortcode?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A shortcode is a special tag such as <code>[example]<\/code> that WordPress replaces with dynamically generated content.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Where_should_I_add_shortcode_PHP_code\"><\/span>Where should I add shortcode PHP code?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">For site functionality, a custom plugin is generally a good choice. A child theme&#8217;s <code>functions.php<\/code> can also be used when the functionality is specifically associated with that theme.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Can_a_shortcode_accept_parameters\"><\/span>Can a shortcode accept parameters?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. Shortcodes can accept attributes such as:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;button text=\"Buy Now\" url=\"https:\/\/example.com\"]<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Can_a_shortcode_contain_content\"><\/span>Can a shortcode contain content?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. You can create enclosed shortcodes:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;box]\nYour content here\n&#91;\/box]<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Should_a_shortcode_echo_or_return_content\"><\/span>Should a shortcode echo or return content?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A shortcode callback should return its generated content.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Can_shortcodes_be_used_in_PHP_templates\"><\/span>Can shortcodes be used in PHP templates?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. You can process one using:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo do_shortcode('&#91;my_shortcode]');<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Are_shortcodes_still_useful_in_WordPress\"><\/span>Are shortcodes still useful in WordPress?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. They remain useful for simple reusable dynamic content and for compatibility with existing WordPress sites, although custom blocks are often a better choice for complex visual editing experiences.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Final_Thoughts\"><\/span>Final Thoughts<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Creating a WordPress shortcode is a straightforward way to turn reusable PHP functionality into a simple content tag.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A basic shortcode requires only two main components: a PHP callback function and <code>add_shortcode()<\/code>. From there, you can add attributes, enclosed content, dynamic data, HTML output, and styling to create more powerful components.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For small projects, a shortcode can be added through a child theme or code snippets solution. For functionality that should survive theme changes, a custom plugin is usually a more maintainable approach.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As your WordPress development skills grow, shortcodes can also serve as a useful stepping stone toward more advanced solutions such as custom plugins, REST API integrations, and custom Gutenberg blocks.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"How to Create a WordPress Shortcode WordPress shortcodes provide a simple way to insert dynamic content into posts,&hellip;","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"csco_display_header_overlay":false,"csco_singular_sidebar":"","csco_page_header_type":"","footnotes":""},"categories":[134],"tags":[],"class_list":["post-2650","post","type-post","status-publish","format-standard","category-wordpress-web-hosting","cs-entry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Create a WordPress Shortcode? - Web Hosting Blogs by Ehostpiya | Tips and Tricks<\/title>\n<meta name=\"description\" content=\"How to Create a WordPress Shortcode? - Wordpress\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Create a WordPress Shortcode? - Web Hosting Blogs by Ehostpiya | Tips and Tricks\" \/>\n<meta property=\"og:description\" content=\"How to Create a WordPress Shortcode? - Wordpress\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Hosting Blogs by Ehostpiya | Tips and Tricks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/facebook.com\/ehostpiya\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-01T11:48:42+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-10-01T11:48:59+00:00\" \/>\n<meta name=\"author\" content=\"Vandeeta\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Vandeeta\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/ehostpiya.in\\\/blog\\\/how-to-create-a-wordpress-shortcode\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ehostpiya.in\\\/blog\\\/how-to-create-a-wordpress-shortcode\\\/\"},\"author\":{\"name\":\"Vandeeta\",\"@id\":\"https:\\\/\\\/ehostpiya.in\\\/blog\\\/#\\\/schema\\\/person\\\/7e99667266ef1b118ad734c1c035d796\"},\"headline\":\"How to Create a WordPress Shortcode?\",\"datePublished\":\"2026-10-01T11:48:42+00:00\",\"dateModified\":\"2026-10-01T11:48:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/ehostpiya.in\\\/blog\\\/how-to-create-a-wordpress-shortcode\\\/\"},\"wordCount\":1927,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/ehostpiya.in\\\/blog\\\/#organization\"},\"articleSection\":[\"Wordpress\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/ehostpiya.in\\\/blog\\\/how-to-create-a-wordpress-shortcode\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ehostpiya.in\\\/blog\\\/how-to-create-a-wordpress-shortcode\\\/\",\"url\":\"https:\\\/\\\/ehostpiya.in\\\/blog\\\/how-to-create-a-wordpress-shortcode\\\/\",\"name\":\"How to Create a WordPress Shortcode? - Web Hosting Blogs by Ehostpiya | Tips and Tricks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ehostpiya.in\\\/blog\\\/#website\"},\"datePublished\":\"2026-10-01T11:48:42+00:00\",\"dateModified\":\"2026-10-01T11:48:59+00:00\",\"description\":\"How to Create a WordPress Shortcode? - Wordpress\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ehostpiya.in\\\/blog\\\/how-to-create-a-wordpress-shortcode\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ehostpiya.in\\\/blog\\\/how-to-create-a-wordpress-shortcode\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ehostpiya.in\\\/blog\\\/how-to-create-a-wordpress-shortcode\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/ehostpiya.in\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Create a WordPress Shortcode?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/ehostpiya.in\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/ehostpiya.in\\\/blog\\\/\",\"name\":\"Web Hosting Blogs by Ehostpiya | Tips and Tricks\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/ehostpiya.in\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/ehostpiya.in\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/ehostpiya.in\\\/blog\\\/#organization\",\"name\":\"Web Hosting Blogs by Ehostpiya | Tips and Tricks\",\"url\":\"https:\\\/\\\/ehostpiya.in\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ehostpiya.in\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/ehostpiya.in\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/08\\\/512.png\",\"contentUrl\":\"https:\\\/\\\/ehostpiya.in\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/08\\\/512.png\",\"width\":512,\"height\":512,\"caption\":\"Web Hosting Blogs by Ehostpiya | Tips and Tricks\"},\"image\":{\"@id\":\"https:\\\/\\\/ehostpiya.in\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/facebook.com\\\/ehostpiya\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/ehostpiya.in\\\/blog\\\/#\\\/schema\\\/person\\\/7e99667266ef1b118ad734c1c035d796\",\"name\":\"Vandeeta\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/ee031298008d633e52bec71ce70d11a0b605dc666af42cdd52a950f061ad9f08?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/ee031298008d633e52bec71ce70d11a0b605dc666af42cdd52a950f061ad9f08?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/ee031298008d633e52bec71ce70d11a0b605dc666af42cdd52a950f061ad9f08?s=96&d=mm&r=g\",\"caption\":\"Vandeeta\"},\"sameAs\":[\"https:\\\/\\\/ehostpiya.in\\\/blog\"],\"url\":\"https:\\\/\\\/ehostpiya.in\\\/blog\\\/author\\\/ehostpiya_blog\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Create a WordPress Shortcode? - Web Hosting Blogs by Ehostpiya | Tips and Tricks","description":"How to Create a WordPress Shortcode? - Wordpress","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/","og_locale":"en_US","og_type":"article","og_title":"How to Create a WordPress Shortcode? - Web Hosting Blogs by Ehostpiya | Tips and Tricks","og_description":"How to Create a WordPress Shortcode? - Wordpress","og_url":"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/","og_site_name":"Web Hosting Blogs by Ehostpiya | Tips and Tricks","article_publisher":"https:\/\/facebook.com\/ehostpiya","article_published_time":"2026-10-01T11:48:42+00:00","article_modified_time":"2026-10-01T11:48:59+00:00","author":"Vandeeta","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Vandeeta","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#article","isPartOf":{"@id":"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/"},"author":{"name":"Vandeeta","@id":"https:\/\/ehostpiya.in\/blog\/#\/schema\/person\/7e99667266ef1b118ad734c1c035d796"},"headline":"How to Create a WordPress Shortcode?","datePublished":"2026-10-01T11:48:42+00:00","dateModified":"2026-10-01T11:48:59+00:00","mainEntityOfPage":{"@id":"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/"},"wordCount":1927,"commentCount":0,"publisher":{"@id":"https:\/\/ehostpiya.in\/blog\/#organization"},"articleSection":["Wordpress"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/","url":"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/","name":"How to Create a WordPress Shortcode? - Web Hosting Blogs by Ehostpiya | Tips and Tricks","isPartOf":{"@id":"https:\/\/ehostpiya.in\/blog\/#website"},"datePublished":"2026-10-01T11:48:42+00:00","dateModified":"2026-10-01T11:48:59+00:00","description":"How to Create a WordPress Shortcode? - Wordpress","breadcrumb":{"@id":"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/ehostpiya.in\/blog\/how-to-create-a-wordpress-shortcode\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ehostpiya.in\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Create a WordPress Shortcode?"}]},{"@type":"WebSite","@id":"https:\/\/ehostpiya.in\/blog\/#website","url":"https:\/\/ehostpiya.in\/blog\/","name":"Web Hosting Blogs by Ehostpiya | Tips and Tricks","description":"","publisher":{"@id":"https:\/\/ehostpiya.in\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ehostpiya.in\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/ehostpiya.in\/blog\/#organization","name":"Web Hosting Blogs by Ehostpiya | Tips and Tricks","url":"https:\/\/ehostpiya.in\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ehostpiya.in\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/ehostpiya.in\/blog\/wp-content\/uploads\/2026\/08\/512.png","contentUrl":"https:\/\/ehostpiya.in\/blog\/wp-content\/uploads\/2026\/08\/512.png","width":512,"height":512,"caption":"Web Hosting Blogs by Ehostpiya | Tips and Tricks"},"image":{"@id":"https:\/\/ehostpiya.in\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/facebook.com\/ehostpiya"]},{"@type":"Person","@id":"https:\/\/ehostpiya.in\/blog\/#\/schema\/person\/7e99667266ef1b118ad734c1c035d796","name":"Vandeeta","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/ee031298008d633e52bec71ce70d11a0b605dc666af42cdd52a950f061ad9f08?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/ee031298008d633e52bec71ce70d11a0b605dc666af42cdd52a950f061ad9f08?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ee031298008d633e52bec71ce70d11a0b605dc666af42cdd52a950f061ad9f08?s=96&d=mm&r=g","caption":"Vandeeta"},"sameAs":["https:\/\/ehostpiya.in\/blog"],"url":"https:\/\/ehostpiya.in\/blog\/author\/ehostpiya_blog\/"}]}},"_links":{"self":[{"href":"https:\/\/ehostpiya.in\/blog\/wp-json\/wp\/v2\/posts\/2650","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ehostpiya.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ehostpiya.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ehostpiya.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ehostpiya.in\/blog\/wp-json\/wp\/v2\/comments?post=2650"}],"version-history":[{"count":2,"href":"https:\/\/ehostpiya.in\/blog\/wp-json\/wp\/v2\/posts\/2650\/revisions"}],"predecessor-version":[{"id":2652,"href":"https:\/\/ehostpiya.in\/blog\/wp-json\/wp\/v2\/posts\/2650\/revisions\/2652"}],"wp:attachment":[{"href":"https:\/\/ehostpiya.in\/blog\/wp-json\/wp\/v2\/media?parent=2650"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ehostpiya.in\/blog\/wp-json\/wp\/v2\/categories?post=2650"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ehostpiya.in\/blog\/wp-json\/wp\/v2\/tags?post=2650"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}