Add query string to data-href

I am trying to add a string after an url inside data-href using jQuery. I am doing this to make sure that my Facebook comments plugin creates a separate thread for each page that loads the comments plugin.

Ideally, what should be added after the data-href url is ?st=<?php echo $post->post_name;?> – but not sure how to implement this PHP from WordPress into a jQuery code.

I have tried several jQuery examples, but none have worked so far.

What the comments plugin code is now:

<div class="fb-comments" data-href="https://myurl.com" data-width="100%" data-numposts="3" data-colorscheme="light"></div>

I need a jQuery code that changes it to:

<div class="fb-comments" data-href="https://myurl.com/?st=post_slug" data-width="100%" data-numposts="3" data-colorscheme="light"></div>

with post_slug being the slug that WordPress creates for each individual post.


Source: wordpress

Leave a Reply