{"id":2073,"date":"2017-11-07T13:44:36","date_gmt":"2017-11-07T08:44:36","guid":{"rendered":"https:\/\/thedevcouple.com\/?p=2073"},"modified":"2017-11-13T21:12:32","modified_gmt":"2017-11-13T16:12:32","slug":"create-custom-wordpress-shortcodes","status":"publish","type":"post","link":"https:\/\/thedevcouple.com\/create-custom-wordpress-shortcodes\/","title":{"rendered":"How to Create Custom WordPress Shortcodes?"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">While learning WordPress plugin development, you come across the\u00a0<\/span><strong><a href=\"https:\/\/codex.wordpress.org\/Shortcode_API\" rel=\"nofollow noopener\" target=\"_blank\">shortcodes API<\/a><\/strong><span style=\"font-weight: 400;\">. As a beginner, this is something which I also found quite interesting. It allows me to create small yet nifty plugins quickly. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">In this post, I will be explaining what are WordPress shortcodes and how you can utilize the shortcodes API in plugin development. <\/span><\/p>\n<div class=\"eckosc eckosc_full_width_block\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-2088 size-full\" src=\"https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/10\/Learn-to-Create-WordPress-Shortcode-via-plugins.png\" alt=\"\" width=\"1920\" height=\"1080\" srcset=\"https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/10\/Learn-to-Create-WordPress-Shortcode-via-plugins.png 1920w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/10\/Learn-to-Create-WordPress-Shortcode-via-plugins-300x169.png 300w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/10\/Learn-to-Create-WordPress-Shortcode-via-plugins-768x432.png 768w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/10\/Learn-to-Create-WordPress-Shortcode-via-plugins-1024x576.png 1024w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/10\/Learn-to-Create-WordPress-Shortcode-via-plugins-1680x945.png 1680w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/10\/Learn-to-Create-WordPress-Shortcode-via-plugins-1240x698.png 1240w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/10\/Learn-to-Create-WordPress-Shortcode-via-plugins-860x484.png 860w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/10\/Learn-to-Create-WordPress-Shortcode-via-plugins-680x383.png 680w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/10\/Learn-to-Create-WordPress-Shortcode-via-plugins-500x281.png 500w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/10\/Learn-to-Create-WordPress-Shortcode-via-plugins-400x225.png 400w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/10\/Learn-to-Create-WordPress-Shortcode-via-plugins-200x113.png 200w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/10\/Learn-to-Create-WordPress-Shortcode-via-plugins-50x28.png 50w\" sizes=\"(max-width: 1920px) 100vw, 1920px\"><\/div>\n<h2><span style=\"font-weight: 400;\">Shortcodes<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Shortcodes are used to insert <strong>dynamic content<\/strong> into WordPress <em>posts<\/em> and <em>pages<\/em>.\u00a0<\/span><span style=\"font-weight: 400;\">Shortcodes are enclosed in the square brackets <code>[ ]<\/code>. Based upon the text inside the brackets, it is replaced by the content generated by a PHP function, defined at the back-end.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Shortcodes are pretty simple to create and use. Let&#8217;s create a shortcode that will display the WPCouple logo. Let&#8217;s name it wpc-logo and its shortcode would look like this<\/span><span style=\"font-weight: 400;\">:<\/span><\/p>\n<div class=\"eckosc eckosc_contrast_block\"><div class=\"eckosc_contrast_block_inner\">[wpc-logo]<\/div><\/div>\n<p><span style=\"font-weight: 400;\">It\u2019s the simplest sort of the shortcode that you\u2019ll ever encounter, i.e. shortcode name in the square brackets. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">There are advanced forms of shortcodes as well, where you can specify the parameters and even add some content. A self-closing shortcode with parameters might look like this:<\/span><\/p>\n<div class=\"eckosc eckosc_contrast_block\"><div class=\"eckosc_contrast_block_inner\">[wpc-logo size=&#8221;120&#8243;]<\/div><\/div>\n<p><span style=\"font-weight: 400;\">Where <code>120<\/code> specifies the width of the logo in pixels. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">You can go ahead and even add some text preceding the logo:<\/span><\/p>\n<div class=\"eckosc eckosc_contrast_block\"><div class=\"eckosc_contrast_block_inner\">[wpc-logo size=&#8221;300&#8243;]WPCoulple Logo[\/wpc-logo]<\/div><\/div>\n<h2><span style=\"font-weight: 400;\">Creating a Shortcode<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">To create a shortcode, you need to do the following three things:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Write a PHP function that will be invoked when the shortcode is called.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Add the shortcode to WordPress using a unique identifier.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Hook the function into WordPress.<\/span><\/li>\n<\/ol>\n<h2><span style=\"font-weight: 400;\">Simple Shortcodes<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">In this part, you\u2019ll learn about creating a simple shortcode like <code>[wpc-logo]<\/code> using\u00a0a WordPress plugin.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Let\u2019s say the main file of the plugin is named as <code>wpc-logo<\/code><code>.php<\/code>\u00a0Now, follow the steps to create the shortcode.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Writing A PHP Function<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">In your main PHP file, define a function which returns the WPCouple logo.<\/span><\/p>\n<div class=\"oembed-gist\"><script src=\"https:\/\/gist.github.com\/MrSaqibAmeen\/0f57e85eac5e9750cc073d8919cca9d5.js\"><\/script><noscript>View the code on <a href=\"https:\/\/gist.github.com\/MrSaqibAmeen\/0f57e85eac5e9750cc073d8919cca9d5\" rel=\"nofollow noopener\" target=\"_blank\">Gist<\/a>.<\/noscript><\/div>\n<h3><span style=\"font-weight: 400;\">Adding Shortcode to WordPress<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Once you\u2019re done writing the PHP function, next step is to register the shortcode with WordPress. For this, you write a simple register function:<\/span><\/p>\n<div class=\"oembed-gist\"><script src=\"https:\/\/gist.github.com\/MrSaqibAmeen\/9def1a0e649c8b23a83d34097c57c9b6.js\"><\/script><noscript>View the code on <a href=\"https:\/\/gist.github.com\/MrSaqibAmeen\/9def1a0e649c8b23a83d34097c57c9b6\" rel=\"nofollow noopener\" target=\"_blank\">Gist<\/a>.<\/noscript><\/div>\n<p><span style=\"font-weight: 400;\">The first argument of the add_shortcode function is the <strong>name<\/strong> of the shortcode. The second argument is the <strong>name of the function<\/strong> to be called when the shortcode is used.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Technically, you can say when this function is called; it adds the shortcode <em>wpc-logo<\/em> to WordPress. And whenever the shortcode <em>wpc-logo<\/em> is used, it will call the function <em><span class=\"pl-en\">wpc_get_logo<\/span>()<\/em>.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Hooking Function with WordPress<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">The next step is to hook the function to WordPress. It will register the shortcode every time you load your WordPress site. You&#8217;ll be using <strong>init action<\/strong> to hook the registration function. <\/span><\/p>\n<div class=\"oembed-gist\"><script src=\"https:\/\/gist.github.com\/MrSaqibAmeen\/721c02dec2c034a12611632f746e7574.js\"><\/script><noscript>View the code on <a href=\"https:\/\/gist.github.com\/MrSaqibAmeen\/721c02dec2c034a12611632f746e7574\" rel=\"nofollow noopener\" target=\"_blank\">Gist<\/a>.<\/noscript><\/div>\n<p><span style=\"font-size: 1.125rem;\">Shortcode In Action<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Install and activate the plugin. Create a new post or page and insert the shortcode:\u00a0<\/span><span style=\"font-weight: 400;\"><code>[wpc-logo]<\/code><\/span><\/p>\n<p><span style=\"font-weight: 400;\">Publish the post and check out the post.<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><div class=\"eckosc eckosc_full_width_block\"><\/span><\/p>\n<p><span style=\"font-weight: 400;\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-2408 size-full\" src=\"https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-logo-post.png\" alt=\"\" width=\"1600\" height=\"929\" srcset=\"https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-logo-post.png 1600w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-logo-post-300x174.png 300w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-logo-post-768x446.png 768w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-logo-post-1024x595.png 1024w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-logo-post-1240x720.png 1240w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-logo-post-860x499.png 860w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-logo-post-680x395.png 680w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-logo-post-500x290.png 500w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-logo-post-400x232.png 400w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-logo-post-250x145.png 250w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-logo-post-200x116.png 200w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-logo-post-150x87.png 150w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-logo-post-100x58.png 100w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-logo-post-76x44.png 76w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-logo-post-50x29.png 50w\" sizes=\"(max-width: 1600px) 100vw, 1600px\"><\/div><\/span><\/p>\n<p><span style=\"font-weight: 400;\">It will look like this:<\/span><\/p>\n<div class=\"eckosc eckosc_full_width_block\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-2409 size-full\" src=\"https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-logo-shortcode.png\" alt=\"\" width=\"1600\" height=\"929\" srcset=\"https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-logo-shortcode.png 1600w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-logo-shortcode-300x174.png 300w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-logo-shortcode-768x446.png 768w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-logo-shortcode-1024x595.png 1024w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-logo-shortcode-1240x720.png 1240w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-logo-shortcode-860x499.png 860w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-logo-shortcode-680x395.png 680w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-logo-shortcode-500x290.png 500w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-logo-shortcode-400x232.png 400w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-logo-shortcode-250x145.png 250w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-logo-shortcode-200x116.png 200w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-logo-shortcode-150x87.png 150w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-logo-shortcode-100x58.png 100w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-logo-shortcode-76x44.png 76w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-logo-shortcode-50x29.png 50w\" sizes=\"(max-width: 1600px) 100vw, 1600px\"><\/div>\n<h2><span style=\"font-weight: 400;\">Shortcodes With Parameters<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">So far, you&#8217;ve learned about how to create simple shortcodes without any parameters. Now, I&#8217;ll move on to creating the shortcodes with parameters and enclosing shortcodes.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In this section you will know how to create shortcodes with a structure like this:\u00a0<\/span><span style=\"font-weight: 400;\"><code>[wpc-logo size=\"120\"]<\/code><\/span><\/p>\n<p><span style=\"font-weight: 400;\">Where <code>120<\/code> is the size of the logo in pixels.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Writing A PHP Function<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">For this type of shortcode, I&#8217;ll add a parameter <code>$atts<\/code> in the function. Inside the function declaration, I used\u00a0<\/span><span style=\"font-weight: 400;\"><code>shortcode_atts()<\/code> <\/span><span style=\"font-weight: 400;\">function to extract and manage the arguments. Now my\u00a0<code>wpc_get_logo<\/code>\u00a0function looks like this:<\/span><\/p>\n<div class=\"oembed-gist\"><script src=\"https:\/\/gist.github.com\/MrSaqibAmeen\/458bc993ef1bc4f5ebb104387702faef.js\"><\/script><noscript>View the code on <a href=\"https:\/\/gist.github.com\/MrSaqibAmeen\/458bc993ef1bc4f5ebb104387702faef\" rel=\"nofollow noopener\" target=\"_blank\">Gist<\/a>.<\/noscript><\/div>\n<p><span style=\"font-weight: 400;\">The function <\/span><span style=\"font-weight: 400;\"><code>shortcode_atts<\/code> <\/span><span style=\"font-weight: 400;\">extracts the values of the parameters and assigns it to <\/span><span style=\"font-weight: 400;\"><code>$arguments<\/code><\/span><span style=\"font-weight: 400;\"> array. Where <\/span><span style=\"font-weight: 400;\"><code>\u2018size\u2019 =&gt; null<\/code> <\/span><span style=\"font-weight: 400;\">assigns a null value to the size. Then I checked if the value is not null, then add it to the width of the logo and return it. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">The remaining two functions \u2014 i.e., adding shortcode, and hooking the function \u2014 remains the same. <\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Shortcode In Action<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Save the changes in the .php file of your plugin and create a new post with the argument, let\u2019s say <\/span><span style=\"font-weight: 400;\"><code>size=\"120\"<\/code><\/span><span style=\"font-weight: 400;\">. Publish the post and view it. <\/span><\/p>\n<div class=\"eckosc eckosc_full_width_block\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-2410 size-full\" src=\"https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-shortcode-with-parameters.png\" alt=\"\" width=\"1600\" height=\"929\" srcset=\"https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-shortcode-with-parameters.png 1600w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-shortcode-with-parameters-300x174.png 300w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-shortcode-with-parameters-768x446.png 768w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-shortcode-with-parameters-1024x595.png 1024w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-shortcode-with-parameters-1240x720.png 1240w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-shortcode-with-parameters-860x499.png 860w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-shortcode-with-parameters-680x395.png 680w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-shortcode-with-parameters-500x290.png 500w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-shortcode-with-parameters-400x232.png 400w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-shortcode-with-parameters-250x145.png 250w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-shortcode-with-parameters-200x116.png 200w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-shortcode-with-parameters-150x87.png 150w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-shortcode-with-parameters-100x58.png 100w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-shortcode-with-parameters-76x44.png 76w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wp-couple-shortcode-with-parameters-50x29.png 50w\" sizes=\"(max-width: 1600px) 100vw, 1600px\"><\/div>\n<p>It will look like this:<\/p>\n<div class=\"eckosc eckosc_full_width_block\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-2411 size-full\" src=\"https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/WP-Couple-ShortCode-Preview-With-Parameters.png\" alt=\"\" width=\"1600\" height=\"929\" srcset=\"https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/WP-Couple-ShortCode-Preview-With-Parameters.png 1600w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/WP-Couple-ShortCode-Preview-With-Parameters-300x174.png 300w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/WP-Couple-ShortCode-Preview-With-Parameters-768x446.png 768w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/WP-Couple-ShortCode-Preview-With-Parameters-1024x595.png 1024w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/WP-Couple-ShortCode-Preview-With-Parameters-1240x720.png 1240w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/WP-Couple-ShortCode-Preview-With-Parameters-860x499.png 860w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/WP-Couple-ShortCode-Preview-With-Parameters-680x395.png 680w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/WP-Couple-ShortCode-Preview-With-Parameters-500x290.png 500w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/WP-Couple-ShortCode-Preview-With-Parameters-400x232.png 400w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/WP-Couple-ShortCode-Preview-With-Parameters-250x145.png 250w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/WP-Couple-ShortCode-Preview-With-Parameters-200x116.png 200w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/WP-Couple-ShortCode-Preview-With-Parameters-150x87.png 150w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/WP-Couple-ShortCode-Preview-With-Parameters-100x58.png 100w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/WP-Couple-ShortCode-Preview-With-Parameters-76x44.png 76w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/WP-Couple-ShortCode-Preview-With-Parameters-50x29.png 50w\" sizes=\"(max-width: 1600px) 100vw, 1600px\"><\/div>\n<h2><span style=\"font-weight: 400;\">Shortcodes With Content<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Now, let&#8217;s jump to creating <strong>shortcodes with content (a.k.a enclosing shortcodes).<\/strong>\u00a0Here, I\u2019ll create a shortcode which will look like this:<\/span><\/p>\n<div class=\"eckosc eckosc_contrast_block\"><div class=\"eckosc_contrast_block_inner\">[wpc-logo size=&#8221;300&#8243;]WPCoulple Logo[\/wpc-logo]<\/div><\/div>\n<h3><span style=\"font-weight: 400;\">Writing a PHP Function <\/span><\/h3>\n<p>Once again, the only thing which is different in this type of shortcode is the PHP function. This time it gets another attribute i.e.\u00a0<span style=\"font-weight: 400;\"><code>$content<\/code>.<\/span><span style=\"font-weight: 400;\"> This variable contains the <strong>content<\/strong> enclosed between the opening and closing tags of the shortcode. Now, our PHP function looks like this:<\/span><\/p>\n<div class=\"oembed-gist\"><script src=\"https:\/\/gist.github.com\/MrSaqibAmeen\/beee5dabb2e0f5a73f6cea8abd101072.js\"><\/script><noscript>View the code on <a href=\"https:\/\/gist.github.com\/MrSaqibAmeen\/beee5dabb2e0f5a73f6cea8abd101072\" rel=\"nofollow noopener\" target=\"_blank\">Gist<\/a>.<\/noscript><\/div>\n<p><span style=\"font-weight: 400;\">Here, I am only appending the content in H2 tags. It will display the content of the shortcodes as a heading for your logo.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Shortcode In Action<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Save the changes in the .php file of your plugin and create a new post with the argument, let\u2019s say <\/span><span style=\"font-weight: 400;\"><code>size=\"300\"<\/code><\/span><span style=\"font-weight: 400;\">, this time. Publish the post and view it.<\/span><\/p>\n<div class=\"eckosc eckosc_full_width_block\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-2412 size-full\" src=\"https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wpcouple-shortcode-with-content-post.png\" alt=\"\" width=\"1600\" height=\"929\" srcset=\"https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wpcouple-shortcode-with-content-post.png 1600w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wpcouple-shortcode-with-content-post-300x174.png 300w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wpcouple-shortcode-with-content-post-768x446.png 768w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wpcouple-shortcode-with-content-post-1024x595.png 1024w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wpcouple-shortcode-with-content-post-1240x720.png 1240w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wpcouple-shortcode-with-content-post-860x499.png 860w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wpcouple-shortcode-with-content-post-680x395.png 680w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wpcouple-shortcode-with-content-post-500x290.png 500w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wpcouple-shortcode-with-content-post-400x232.png 400w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wpcouple-shortcode-with-content-post-250x145.png 250w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wpcouple-shortcode-with-content-post-200x116.png 200w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wpcouple-shortcode-with-content-post-150x87.png 150w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wpcouple-shortcode-with-content-post-100x58.png 100w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wpcouple-shortcode-with-content-post-76x44.png 76w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/wpcouple-shortcode-with-content-post-50x29.png 50w\" sizes=\"(max-width: 1600px) 100vw, 1600px\"><\/div>\n<p>It will look like this:<\/p>\n<div class=\"eckosc eckosc_full_width_block\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-2413 size-large\" src=\"https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/WP-Couple-Shortcode-preview-with-content-1024x595.png\" alt=\"\" width=\"1024\" height=\"595\" srcset=\"https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/WP-Couple-Shortcode-preview-with-content-1024x595.png 1024w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/WP-Couple-Shortcode-preview-with-content-300x174.png 300w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/WP-Couple-Shortcode-preview-with-content-768x446.png 768w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/WP-Couple-Shortcode-preview-with-content-1240x720.png 1240w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/WP-Couple-Shortcode-preview-with-content-860x499.png 860w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/WP-Couple-Shortcode-preview-with-content-680x395.png 680w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/WP-Couple-Shortcode-preview-with-content-500x290.png 500w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/WP-Couple-Shortcode-preview-with-content-400x232.png 400w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/WP-Couple-Shortcode-preview-with-content-250x145.png 250w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/WP-Couple-Shortcode-preview-with-content-200x116.png 200w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/WP-Couple-Shortcode-preview-with-content-150x87.png 150w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/WP-Couple-Shortcode-preview-with-content-100x58.png 100w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/WP-Couple-Shortcode-preview-with-content-76x44.png 76w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/WP-Couple-Shortcode-preview-with-content-50x29.png 50w, https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/11\/WP-Couple-Shortcode-preview-with-content.png 1600w\" sizes=\"(max-width: 1024px) 100vw, 1024px\"><\/div>\n<p>&nbsp;<\/p>\n<h2><span style=\"font-weight: 400;\">What You&#8217;ve Learned So Far?<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">I&#8217;m sure by now you&#8217;ll be well-familiar to the different types of the shortcodes and how to create them on your own. I tried to keep it as simple as possible. If you face any problem while following the guides, let me know in the comments. <\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>While learning WordPress plugin development, you do come across the\u00a0shortcodes API. As a beginner, this is something which I also found quite interesting. In this post, I will be explaining what WordPress shortcodes are and how you can utilize the shortcodes API in plugin development.<\/p>\n","protected":false},"author":4,"featured_media":2087,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":""},"categories":[6],"tags":[62,61],"coauthors":[],"jetpack_featured_media_url":"https:\/\/thedevcouple.com\/wp-content\/uploads\/2017\/10\/Learn-to-Create-WordPress-Shortcode-through-plugins-Featured-Image.png","amp_enabled":true,"_links":{"self":[{"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/posts\/2073"}],"collection":[{"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/comments?post=2073"}],"version-history":[{"count":0,"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/posts\/2073\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/media\/2087"}],"wp:attachment":[{"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/media?parent=2073"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/categories?post=2073"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/tags?post=2073"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/thedevcouple.com\/api\/wp\/v2\/coauthors?post=2073"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}