I am trying to add dynamic Facebook og tags to my Wordpress site. I add them to the single.php file instead of the usually recommended functions.php file, because I have the code below that for the Facebook application that I created, which needs to be executed every time someone views a single blog post, because then he goes to his Facebook that they read this particular post. I do not want to use the plugin because some of my plugins were in conflict with each other, and it was a mess to sort it out. My biggest problem is that I need the og:url tag to be dynamic, although there should also be og:title , og:description , og:image tags, etc. Here is the code that I have at the top of my single.php file:
EDIT: HERE A WORKING CODE WHICH I NOW USE. THANKS FOR EVERY HELP:
<?php $params = array(); if(count($_GET) > 0) { $params = $_GET; } else { $params = $_POST; } <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# internetlolsapp: http://ogp.me/ns/fb/internetlolsapp#"> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <meta property="fb:app_id" content="378076268920252" /> <meta property="og:site_name" content="meta site name"/> <meta property="og:url" content="<?php echo 'http://internetlols.com'.$_SERVER['REQUEST_URI']; ?>"/> <meta property="og:type" content="internetlolsapp:<?php echo $params['type']; ?>"/> <meta property="og:description" content="<?php echo $params['description']; ?>"/> </head> </html> <script type="text/javascript"> function postView() { FB.api( '/me/internetlolsapp:view', 'post', { picture: '<?php echo 'http:</script> </head> <body> <div id="fb-root"></div> <script> window.fbAsyncInit = function() { FB.init({ appId : '378076268920252', </script> </body> <body onload='postView()'> </html>
I am trying to execute the code located here: Dynamically generates Facebook Open Graph meta tags and it is sent to my Facebook timeline whenever I read a blog post, but for the title, it naturally publishes a “default title” and when I click the default name link on my Facebook timeline, it sends me to the url for one .php with a bunch of bullshit at the end of the url
http://MYSITE.com/wp-content/themes/twentyeleven/single.php?fb_action_ids=10151048340001514&fb_action_types=internetlolsapp%3Aview&fb_source=other_multiline
instead of the blog url. I am wondering if it has anything to do with the URL that I placed on the 3rd line after "FB.api", but everything I tried to put there prevents the application from publishing anything at all my Facebook timeline when I read a blog post.
Any ideas how to fix this? I pulled my hair for so long. Any help would be greatly appreciated! Thanks in advance.
php facebook meta-tags wordpress
RK Jun 17 2018-12-12T00: 00Z
source share