438 posts
  • Has been part of the Envato Community for over 2 years
  • Has sold $5,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Located in Europe
+1 more
Pixelous says

Hello, I have a shortcode which should output a javascript:

function my_shortcode( $atts, $content = null ) {    
        extract( shortcode_atts( array(
        ), $atts) );
$output = '';
$output .= '// javascript with php variables goes gere';
return $output;
}
add_shortcode('my_shortcode', 'index_my_shortcode');

As u can see, my shortcode outputs a javascript with php variables, but I am interesting is there a way to output this javascript under the footer? I know there is a way to serialise script but at current moment I am interesting to place javascript under the footer. As u know there is a wp_footer function http://codex.wordpress.org/Function_Reference/wp_footer But it’s possible to use it to place my javascript with shortcode’s php variables? Hope to hear a suggestions from someone, thanks.

3072 posts
  • Has referred 50+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Had an item featured on Envato Market
+5 more
wickedpixel says

I would manage this thing in another way. Don’t write javascript with the shortcode, instead write the data you need in the tag attributes or as hidden tags. Later, the javascript that starts in the footer will use that content to do stuff needed.
For simple values use the html tag attribute “data-settingname”....

3243 posts
  • Has sold $5,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Located in United States
  • Has been part of the Envato Community for over 4 years
+1 more
organicbee says

I would manage this thing in another way. Don’t write javascript with the shortcode, instead write the data you need in the tag attributes or as hidden tags. Later, the javascript that starts in the footer will use that content to do stuff needed.
For simple values use the html tag attribute “data-settingname”....

cough http://codex.wordpress.org/Function_Reference/wp_localize_script

then use a meta-box/options panel to control it

438 posts
  • Has been part of the Envato Community for over 2 years
  • Has sold $5,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Located in Europe
+1 more
Pixelous says

I would manage this thing in another way. Don’t write javascript with the shortcode, instead write the data you need in the tag attributes or as hidden tags. Later, the javascript that starts in the footer will use that content to do stuff needed.
For simple values use the html tag attribute “data-settingname”....

wickedpixel, could u provide an example, please or u, Chris?

3243 posts
  • Has sold $5,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Located in United States
  • Has been part of the Envato Community for over 4 years
+1 more
organicbee says


I would manage this thing in another way. Don’t write javascript with the shortcode, instead write the data you need in the tag attributes or as hidden tags. Later, the javascript that starts in the footer will use that content to do stuff needed.
For simple values use the html tag attribute “data-settingname”....
wickedpixel, could u provide an example, please or u, Chris?

what exactly are you trying to do? post the full code/explain it a bit

3072 posts
  • Has referred 50+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Had an item featured on Envato Market
+5 more
wickedpixel says

here: http://pastie.org/4344420
Anyway, this method works with scripts that start on window ready event too… or with footer, etc.

438 posts
  • Has been part of the Envato Community for over 2 years
  • Has sold $5,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Located in Europe
+1 more
Pixelous says

here: http://pastie.org/4344420

Thanks for your reply, seems interesting solution, if I have several div id=”cool-viewer-’. $id .’” ? U know, div id=”cool-viewer-1”, div id=”cool-viewer-2”, div id=”cool-viewer-3”, etc. Should I use jquery .each function?

3072 posts
  • Has referred 50+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Had an item featured on Envato Market
+5 more
wickedpixel says

sure. You don’t even need unique id’s… you can use a class instead and use the .each on that class…

438 posts
  • Has been part of the Envato Community for over 2 years
  • Has sold $5,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Located in Europe
+1 more
Pixelous says



I would manage this thing in another way. Don’t write javascript with the shortcode, instead write the data you need in the tag attributes or as hidden tags. Later, the javascript that starts in the footer will use that content to do stuff needed.
For simple values use the html tag attribute “data-settingname”....
wickedpixel, could u provide an example, please or u, Chris?
what exactly are you trying to do? post the full code/explain it a bit

Chris, actually a code big enought.

by
by
by
by
by
by