-
AuthorPosts
-
April 14, 2015 at 8:01 pm #428425
Hi i have a request to insert OG meta tags on a site,due to a app needing it for posting on fb thru the app.
I have all the data that needs to be added, question is where should i add it ?
Is there a plugin best suited for this or is it as simple as adding the data to a file ?
<meta property="og:image" content="http://www.golfbaren.se/wp-content/themes/golfbaren/golfbaren/img/fb_logo.jpg" /> <meta property="og:site_name" content="Golfbaren.se" /> <meta property="og:title" content="Golfbaren | Minigolf och maximys" /> <meta property="og:description" content="Kom och spela minigolf på konstgräs av bästa kvalitet, en putt från T-banan och alldeles intill Kristinebergs Slottspark." /> <meta property="og:type" content="website" /> <meta property="og:url" content="http://www.golfbaren.se" />
Any input much appreciated!
Thanx!
April 14, 2015 at 9:34 pm #428487So from what i’v read the og meta should be added to the functions.php
I tried this from this guide
//Adding the Open Graph in the Language Attributes 02 function add_opengraph_doctype( $output ) { 03 return $output . ' xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"'; 04 } 05 add_filter('language_attributes', 'add_opengraph_doctype'); 06 07 //Lets add Open Graph Meta Info 08 09 function insert_fb_in_head() { 10 global $post; 11 if ( !is_singular()) //if it is not a post or a page 12 return; 13 echo '<meta property="fb:admins" content="148882508634598"/>'; 14 echo '<meta property="og:title" content="Golfbaren | Minigolf och maximys"/>'; 15 echo '<meta property="og:type" content="website"/>'; 16 echo '<meta property="og:url" content=http://www.golfbaren.se/>'; 17 echo '<meta property="og:site_name" content="Golfbaren.se"/>'; echo '<meta property="og:description" content="Kom och spela minigolf på konstgräs av bästa kvalitet, en putt från T-banan och alldeles intill Kristinebergs Slottspark." />'; 18 if(!has_post_thumbnail( $post->ID )) { //the post does not have featured image, use a default image 19 $default_image="http://example.com/image.jpg"; //replace this with a default image on your server or an image in your media library 20 echo '<meta property="og:image" content="http://www.golfbaren.se/wp-content/themes/golfbaren/golfbaren/img/fb_logo.jpg"/>'; 21 } 22 else{ 23 $thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'medium' ); 24 echo '<meta property="og:image" content="' . esc_attr( $thumbnail_src[0] ) . '"/>'; 25 } 26 echo " 27 "; 28 } 29 add_action( 'wp_head', 'insert_fb_in_head', 5 );
But then i can’t access the site due to a function.php error on the line where i pasted this.
Any idea what i’m doing wrong ?
April 15, 2015 at 12:30 am #428553Hey!
You have line numbers included in your code. Please try copying the code from here – http://pastebin.com/ZPMLD8eK
Best regards,
YigitApril 15, 2015 at 6:46 am #428704Ah thanx!
So should i add this to the functions.php or the functions-enfold.php ?
Also is there a way for a novice like to check if the tags is added and “working” ?
Thanx!
April 15, 2015 at 12:26 pm #428853Hi!
You should add the code to functions.php file. Please post the link to your website after adding the code so we can check it
Cheers!
YigitApril 15, 2015 at 12:32 pm #428861April 15, 2015 at 12:42 pm #428866April 15, 2015 at 12:46 pm #428871Great, thank for the help!!
-
AuthorPosts
- The topic ‘OG meta tags ?’ is closed to new replies.