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.
- Community Superstar
- Item was Featured
- Author was Featured
- Has been a member for 5-6 years
- Won a Competition
- Sold between 50 000 and 100 000 dollars
- Bought between 10 and 49 items
- Referred between 50 and 99 users
- Europe
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 said
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
wickedpixel said
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?
Pixelous said
wickedpixel saidwickedpixel, could u provide an example, please or u, Chris?
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”....
what exactly are you trying to do? post the full code/explain it a bit
- Community Superstar
- Item was Featured
- Author was Featured
- Has been a member for 5-6 years
- Won a Competition
- Sold between 50 000 and 100 000 dollars
- Bought between 10 and 49 items
- Referred between 50 and 99 users
- Europe
here: http://pastie.org/4344420
Anyway, this method works with scripts that start on window ready event too… or with footer, etc.
wickedpixel said
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?
- Community Superstar
- Item was Featured
- Author was Featured
- Has been a member for 5-6 years
- Won a Competition
- Sold between 50 000 and 100 000 dollars
- Bought between 10 and 49 items
- Referred between 50 and 99 users
- Europe
sure. You don’t even need unique id’s… you can use a class instead and use the .each on that class…
OrganicBeeMedia said
Pixelous saidwhat exactly are you trying to do? post the full code/explain it a bit
wickedpixel saidwickedpixel, could u provide an example, please or u, Chris?
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”....
Chris, actually a code big enought.
