{"id":1914,"date":"2012-12-16T09:18:28","date_gmt":"2012-12-16T09:18:28","guid":{"rendered":"https:\/\/theextremewebdesigns.com\/blog\/?p=1914"},"modified":"2012-12-16T09:18:28","modified_gmt":"2012-12-16T09:18:28","slug":"wordpress-shortcodes-how-to-use-shortcodes-in-wordpress-theme-examples","status":"publish","type":"post","link":"https:\/\/theextremewebdesigns.com\/blog\/wordpress-shortcodes-how-to-use-shortcodes-in-wordpress-theme-examples\/","title":{"rendered":"WordPress Shortcodes: How to use Shortcodes in WordPress Theme Examples"},"content":{"rendered":"<p><strong>Using Shortcodes in WordPress themes:<\/strong> If you are wondering how to use Shortcodes in WordPress Themes, then this article is for you. In this article, I am going to show you how easily you can use shortcodes in any of the existing WordPress themes or a brand new WordPress theme. Read on to find out more.<!--more--><\/p>\n<h2>How to use Shortcodes in WordPress Theme<\/h2>\n<p>Before we move on, let&#8217;s quickly try to understand what a Shortcode is.<\/p>\n<h3>Shortcode:<\/h3>\n<p>It is simply a line of code that when used in conjunction with WordPress theme, widget, plugin, etc. executes the associated function, performs the related operations as written in the code &amp; shows the output result. That&#8217;s it for the definition.<\/p>\n<h3>So how to actually make use of Shortcodes in WordPress Theme?<\/h3>\n<p>There are couple of ways to do this. Following are the examples:<\/p>\n<p><strong>Example 1:<\/strong><\/p>\n<p>Assuming the want to use a shortcode named [my_shortcode] in a WordPress theme, simply copy &amp; paste the following line of code in your theme where you want the output result of the shortcode to appear:<\/p>\n<pre class=\"lang:php decode:true\">&lt;?php echo do_shortcode(\"[my_shortcode]\"); ?&gt;<\/pre>\n<p>By mentioning the do_shortcode() command\u00a0explicity, you thereby indicate to WordPress that you are trying to use a shortcode &amp; thus make it honor your request. In order for this to work, you must have the relevant function by the name\u00a0my_shortcode in your functions.php file (if you are using only a theme) or in the necessary php file (in case you are using the shortcode in a \u00a0plugin).<\/p>\n<p><strong>Example 2:<\/strong><\/p>\n<p>Here&#8217;s an extended example. Let&#8217;s say that you are building a photo gallery &amp; want the shortcode to show the photo gallery in the WordPress theme, so you can follow the code below:<\/p>\n<pre class=\"lang:xhtml decode:true\">[mygallery id=\"12345\" size=\"large\"]<\/pre>\n<p><strong>Associated function for mygallery shortcode (goes in the functions.php file)<\/strong><\/p>\n<pre class=\"lang:php decode:true\">function mygallery_function( $atts )\n{\n\t$gallery_images = '&lt;img src=\"flower.jpg\" width=\"300\" height=\"300\" \/&gt;&lt;br \/&gt;';\n\t$gallery_images .= '&lt;img src=\"apple.jpg\" width=\"300\" height=\"300\" \/&gt;&lt;br \/&gt;';\n\t$gallery_images .= '&lt;img src=\"liberty.jpg\" width=\"300\" height=\"300\" \/&gt;';        \n\n\treturn $gallery_images;\n}\n\nadd_shortcode( 'mygallery ', 'mygallery_function' );<\/pre>\n<p>The above example is very simple &amp;\u00a0minimal. The usage can be extended &amp; customized to our needs.<\/p>\n<h5>Simple, isn&#8217;t it?<\/h5>\n<p>Do you know of any other ways to <strong>use Shortcodes in WordPress themes<\/strong>? Feel free to suggest by commenting below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using Shortcodes in WordPress themes: If you are wondering how to use Shortcodes in WordPress Themes, then this article is for you. In this article, I am going to show you how easily you can use shortcodes in any of the existing WordPress themes or a brand new WordPress theme. Read on to find out [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":114,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[13,11],"tags":[30],"class_list":["post-1914","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tips-and-tricks","category-wordpress-tips-and-tricks","tag-wordpress-tips"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/paBnQX-uS","jetpack_sharing_enabled":true,"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/1914","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/comments?post=1914"}],"version-history":[{"count":0,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/posts\/1914\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/media?parent=1914"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/categories?post=1914"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/theextremewebdesigns.com\/blog\/wp-json\/wp\/v2\/tags?post=1914"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}