I want to change contents of Meta tag dynamically,

Here is the code which which will call the function "changeMetaInformation()" of javascript

<a onclick="changeMetaInformation('<?php  echo Mage::helper('core/url')->getCurrentUrl();?>', '<?php echo $_product->getName()?>')" href="javascript:void(0)" title="<?php echo $this->__('Share on Facebook') ?>"> 

Now here is my function which will change the Meta tag information

function changeMetaInformation(url,name)

    jQuery("head").append('<meta property="og:url" content="'+url+'">');
    jQuery("head").append('<meta property="og:title" content="Supermax">');

    javascript:popWin('https://www.facebook.com/sharer/sharer.php?u='+url+'&t='+name, 'facebook', 'width=640,height=480,left=0,top=0,location=no,status=yes,scrollbars=yes,resizable=yes')

And these are my Meta tags, the content of which I want to change dynamically.

<meta property="og:title" content="Join the best company in the world!" />
<meta property="og:url" content="http://www.sharethis.com" />
<meta property="og:image" content="http://sharethis.com/images/logo.jpg" />
<meta property="og:description" content="ShareThis is its people. It's imperative that we hire smart,innovative people who can work intelligently as we continue to disrupt the very category we created. Come join us!" />

1 Answer 1


you can change content with these below code

  jQuery("meta[property='og\\:url']").attr("content", url);


  • Not working.... Commented Jan 5, 2017 at 9:59
  • 1
    did you remove this code first from top jQuery('meta[property="og:url"]').remove(); Commented Jan 5, 2017 at 9:59
  • @MagentoDeveloper working perfectly for me on mozilla firefox. Commented Jan 5, 2017 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.