Support » Plugins » 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;
    		'type' => 'blog',
    		'cat' => '',
    		'feedpath' => 'feed/',
    		'max' => '10'
    	), $atts));
    	//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="'.$type.$cat.$feedpath.$max..$divid.'"></script>';
    add_shortcode('rssfeedme', 'rssfeedme_func');
Viewing 2 replies - 1 through 2 (of 2 total)
  • BTW, I need to be able to pass the randomly generated div id ($rssfeedme_rand = 'rssfeedme_'.rand(0, 999999);), because I may have more than one. Also, I suspect doing a global $rssfeedme_rand; won’t work, because I may not reliably get the unique values…

    I should read the documentation more… It looks like I need to figure out a combination of the add_action and do_action functions… Will report back when I’ve got it working…

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.