Struggling to use a global variable
-
I am struggling to apply a global variable in a function using code snippets and wonder if there is something I am missing in the way your plugin works. My code is
$dhURL = get_the_permalink(); function facebookshare_function() { global $dhURL; $FBURL = 'https://www.facebook.com/sharer/sharer.php?u='.$dhURL; return $FBURL; } add_shortcode('facebookshare', 'facebookshare_function');The $dhURL is not being appended when running the shortcode. It works correctly if I run
function facebookshare_function() { $dhURL = get_the_permalink(); $FBURL = 'https://www.facebook.com/sharer/sharer.php?u='.$dhURL; return $FBURL; }However I wish to create other shortcodes in the same snippet (eg twitter) and use the same $dhURL variable.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Struggling to use a global variable’ is closed to new replies.