Use shortcode to add div to sidebar & script to wp_footer?
-
I’ve created a shortcode to output my sidebar RSS feeds to a separate server, which caches the results (uses JavaScript to get the feed results).
Any ideas on how to write a shortcode to add div id to sidebar & script to wp_footer? I can either write to one place but not the other, and I need to write to both, because I can’t send the div’s randomly generated ID (so I can have multiple) to wp_footer.
Here’s a snippet.
$rssfeedme_rand = ''; function rssfeedme_func($atts) { global $rssfeedme_rand; extract(shortcode_atts(array( 'type' => 'blog', 'cat' => '', 'feedpath' => 'feed/', 'max' => '10' ), $atts)); $type=($type!='')?'?type='.$type:''; $cat=($cat!='')?'&cat='.$cat:''; $feedpath=($feedpath!='')?'&feedpath='.$feedpath:''; $max=($max>0)?'&max='.$max:''; //build DIV ID w random number for innerHTML $rssfeedme_rand = 'rssfeedme_'.rand(0, 999999); $divid = '&outputDiv='.$rssfeedme_rand; add_action('wp_footer', 'rssfeedme_footer'); return '<div class="rssfeedme"><ul class="rssfeedme_ul"><li class="rssfeedme_li" id="'.$rssfeedme_rand.'" style="list-style:none;background:none;"></li></ul></div>'; } function rssfeedme_footer() { global $rssfeedme_rand; echo '<script type="text/javascript" src="https://sub.domain.com/feeds/rssheads/feedme.php'.$type.$cat.$feedpath.$max..$divid.'"></script>'; } add_shortcode('rssfeedme', 'rssfeedme_func');
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Use shortcode to add div to sidebar & script to wp_footer?’ is closed to new replies.