0

i am working for a php application using codeigniter framework. i have to create a facebook page share link. for that i am trying to set meta tags dynamically.

i have to set Title, Description and Image Url dynamically.

i am using following code to set meta tag in head section

<meta property="og:image" content="http://some path/11.jpg"/>
 <meta property="og:image:secure_url" content="http://somepath/callHealthCondDesc?id=1" />
 <meta property="og:title" content="TITLE" /> 
 <meta property="og:description" content="DESCRIPTION" />

after that setting meta tag dynamically in ready section

  $(this).ready(function() {

$('meta[name=og\\:title]').attr('content', 'new title');
$('meta[name=og\\:description]').attr('content', 'new description');
$('meta[name=og\\:image]').attr('content', 'http://new image url');

}

but it is not constructing the page dynamically with new parameter.

i have checked some similar post

but could not get the working solution for me.

i am not clear where i am doing mistake. please guide me for the issue

Community
  • 1
  • 1
Toman
  • 1,156
  • 1
  • 12
  • 29
  • AFAIK, when sharing a page on social netowrk, it looks for meta tag in HTML, and ignores javascript, dynamically change meta tag won't work this way. – Neverever Jun 18 '15 at 07:58

1 Answers1

2

As i answer to this question even if it's not you exact case, you can't edit dynamically via js or other client site way the OG meta, facebook will use always the original html OG meta.

Case 1

If you are using php and you want make them dynamic you can opt for a solution similar to 2) where you change server side the OG meta when the page is loaded (there are different way i think, a parameter in the url can works if you have only few cases)


Case 2

You can try the Feed dialog share where you can choose the shared parameters. You are no more linked to the OG meta, but you can anyway set them to use in case some user share the page in another way.

Community
  • 1
  • 1
Emanuele Parisio
  • 1,192
  • 8
  • 27