I am trying to make this meta tag always have the current URL of the page it is on.
<meta property="og:url" content="http://shop.famsf.org/do/product/BK5160" />
How would I go about changing a meta tag with JS or JQ?
I am trying to make this meta tag always have the current URL of the page it is on.
<meta property="og:url" content="http://shop.famsf.org/do/product/BK5160" />
How would I go about changing a meta tag with JS or JQ?
Changing Facebook meta tag Content Attribute using JQuery
It is definitely possible to change meta tags using jQuery, but I don't think that's going to accomplish what you want since the meta tags are pulled by the FB scraper. The FB scraper goes out and scrapes your page to read the meta tags.
Editing Meta Tags
You can update the attributes of your page by updating your page's tags. Note that og:title and og:type are only editable initially - after your page receives 50 likes the title becomes fixed, and after your page receives 10,000 likes the type becomes fixed. These properties are fixed to avoid surprising users who have liked the page already. Changing the title or type tags after these limits are reached does nothing, your page retains the original title and type.
For the changes to be reflected on Facebook, you must force your page to be scraped. The page is scraped when an admin for the page clicks the Like button or when the URL is entered into the Facebook URL Linter. You can programmatically force your page to be scraped by cURL'ing the linter. For example ...
https://developers.facebook.com/docs/opengraph/
BUT if you want to do this:
$('meta[property=og\\:url]').attr('content', window.location.href);
Select the element using tagname and attribute. Set the value using .attr()
:
$("meta[property='og:url']").attr("content", location.href);
You just grab a meta tags with the name 'og:url' and set its content attribute like this :
$('meta[property="og:url"]').attr('content', window.location.href);
Property not working i used like that:
$("meta[name='og:url']").attr("content", location.href);