I want to add a string after an url inside data-href using jQuery. I want to make sure that my Facebook comments plugin creates a separate thread for each page that loads the comments plugin.
What should be added after the data-href url is ?st=<?php echo $post->post_name;?>
– but not sure how to implement this in PHP from WordPress into a jQuery code.
right now:
<div class="fb-comments" data-href="https://myurl.com" data-width="100%" data-numposts="3" data-colorscheme="light"></div>
what it should look like with post_slug
being the slug that WordPress creates for each individual post.
<div class="fb-comments" data-href="https://myurl.com/?st=post_slug" data-width="100%" data-numposts="3" data-colorscheme="light"></div>
If you have jQuery in your page then you can use this script block:
Using jquery:
you need to use
json_encode
â this returns the JSON representation of a value. You then can manipulate the data-href with the jQuery.example below.
Get the link
Change the attribute
You can use getAttribute() to get the original and edit it.
Change the “class” to “id” in your html.