{"id":2011,"date":"2019-05-01T21:33:56","date_gmt":"2019-05-01T20:33:56","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=2011"},"modified":"2025-04-10T10:30:52","modified_gmt":"2025-04-10T09:30:52","slug":"shortcodes-general","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/wordpress\/shortcodes\/shortcodes-general","title":{"rendered":".Shortcodes General"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Using the WordPress shortcode feature on a page<\/h4>\n\n\n\n<p>Yes you need to include the square brackets!<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Calling a function from post or page content<\/h4>\n\n\n\n<p>Just add [my_special_shortcode] within any post or page and the function will be called<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/Shortcode: &#91;my_special_shortcode]\nadd_shortcode('my_special_shortcode', 'my_function_Name');\nfunction my_function_Name()\n{\n\n  \/\/-----------------------\n  \/\/----- HTML OUTPUT -----\n  \/\/-----------------------\n  $HtmlOutput = '';\n\n  return($HtmlOutput);\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Passing arguments with a shortcode<\/h4>\n\n\n\n<p>In the wordpress content<\/p>\n\n\n\n<p><strong><em><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">(N.B. keep attributes lowercase, they will get converted to lowercase)<\/mark><\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;my_special_shortcode my_id=12 my_value=\"abc\"]<\/code><\/pre>\n\n\n\n<p>In your function<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>add_shortcode('my_special_shortcode', 'my_function_Name');\nfunction my_function_Name($atts)    \/\/&lt;&lt;&lt;&lt;&lt;&lt;Don't forget the $atts !!!\n{\n  \/\/----- GET SHORTCODE ATTRIBUTES -----\n  \/\/Extract attributes into individual variables, setting default values if not present\n  extract(shortcode_atts(array(\n    'my_id' =&gt; 1,\n    'my_value' =&gt; ''\n  ), $atts));\n\n  \/\/if ($my_id == 12)\n  \/\/...\n\n  \/\/-----------------------\n  \/\/----- HTML OUTPUT -----\n  \/\/-----------------------\n  $HtmlOutput = '';\n\n  return($HtmlOutput);\n}<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Other things you can pass with a shortcode<\/h5>\n\n\n\n<p><a href=\"https:\/\/developer.wordpress.org\/plugins\/shortcodes\/shortcodes-with-parameters\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/developer.wordpress.org\/plugins\/shortcodes\/shortcodes-with-parameters\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Using the WordPress shortcode feature on a page Yes you need to include the square brackets! Calling a function from post or page content Just add [my_special_shortcode] within any post or page and the function will be called Passing arguments with a shortcode In the wordpress content (N.B. keep attributes lowercase, they will get converted [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[166],"tags":[],"class_list":["post-2011","post","type-post","status-publish","format-standard","hentry","category-shortcodes"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2011","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=2011"}],"version-history":[{"count":15,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2011\/revisions"}],"predecessor-version":[{"id":4868,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2011\/revisions\/4868"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=2011"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=2011"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=2011"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}