Wednesday, 15 May 2013

javascript - Unique ID for WordPress shortcodes when used more than once on a page? -



javascript - Unique ID for WordPress shortcodes when used more than once on a page? -

i’m coding wordpress shortcode , has jquery involved. jquery work need utilize div unique #id. if shortcode used once, works fine, if utilize shortcode more 1 time on page, break javascript.

so, i’m wondering if there way utilize unique id every time shortcode called? or way have different id if shortcode used more 1 time on page?

suppose have shortcode function

function my_shortcode() { $my_shortcode='<div id="demo">my content</div>'; homecoming $my_shortcode; } //end function

and jquery

$("#demo").click(function{ autoplay: true, });

you can utilize static variable

static $i = 1; $i++;

and utilize part of id

return "<div id='shortcode-div-{$i}'></div>";

javascript php wordpress shortcode

No comments:

Post a Comment