I’m currently coding a WordPress shortcode and it has some javascript involved. For javascript to work properly I need to use a div with a unique #ID. If the shortcode is used once, it works fine, but if they were to use the shortcode more than once on a page, it would break the javascript.

So, I’m wondering if there is some way to use a unique ID every time the shortcode is called? Or some way to have a different ID if the shortcode is used more than once on a page?

  • Generate and use said ID in your shortcode callback? Just use a static var or something and increment every call. – Rarst Nov 6 '14 at 15:24
  • Or you could use uniqid (for generating that ID) in combination with wp_localize_script or just use a class... – realloc Nov 6 '14 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.