{"id":3684,"date":"2021-02-25T11:19:31","date_gmt":"2021-02-25T11:19:31","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=3684"},"modified":"2026-04-07T12:33:35","modified_gmt":"2026-04-07T11:33:35","slug":"sharing-values-between-shortcodes","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/wordpress\/shortcodes\/sharing-values-between-shortcodes","title":{"rendered":"Sharing values between shortcodes"},"content":{"rendered":"\n<p>You can output a shortcode from a shortcode and within that create an attribute value dynamically of course, but sharing a value from one shortcode triggered function call to another later in a page is presumably not possible.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Use PHP global variables<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">Global Variables<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>$MySharedValue = '';\n$GLOBALS&#91;'MY_SHORTCODE_DATA'] = &#91;];    \/\/Can be good if you may need more than one value<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Shortcode 1<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>function MyShortcode1($atts = &#91;])\n{\n  global $MySharedValue;\n\n  $MySharedValue = 'Hello';\n\n  $GLOBALS&#91;'MY_SHORTCODE_DATA']&#91;'telephone'] = '447700900123';\n\n}<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Shortcode 2<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>function MyShortcode2($atts = &#91;])\n{\n  global $MySharedValue;\n\n  echo $MySharedValue;\n\n  $telephone = $GLOBALS&#91;'MY_SHORTCODE_DATA']&#91;'telephone'] ?? '';\n\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Use javascript<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">.innerHTML<\/h5>\n\n\n\n<p>Use javascript .innerHTML to cause the content of something on the page to be changed once the page is loaded by the browser (which will occur after all of the shortcodes have done their thing server side).<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">function ()<\/h5>\n\n\n\n<p>Have your html output call a javascript function that will be created by another shortcode call, again occurring once the page is loaded by the browser (which will occur after all of the shortcodes have done their thing server side).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can output a shortcode from a shortcode and within that create an attribute value dynamically of course, but sharing a value from one shortcode triggered function call to another later in a page is presumably not possible. Use PHP global variables Global Variables Shortcode 1 Shortcode 2 Use javascript .innerHTML Use javascript .innerHTML to [&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-3684","post","type-post","status-publish","format-standard","hentry","category-shortcodes"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/3684","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=3684"}],"version-history":[{"count":2,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/3684\/revisions"}],"predecessor-version":[{"id":5342,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/3684\/revisions\/5342"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=3684"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=3684"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=3684"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}