Cara Menambahkan Ogg Facebook ke Smart Toko

by | Jul 27, 2018 | 0 comments

Berikut ini adalah cara untuk menambahkan ogg kedalam theme smart toko.
ogg ini berfungsi untuk menyesuaikan gambar produk jika di share / like menggunakan facebook

Tambahkan kode ini ke functions.php

ganti “YOUR USER ID” dengan id facebook anda sebagai admin
dan untuk v7 ke atas gunakan kode ini :

function insert_fb_in_head() {
 global $post;
 if ( !is_singular()) //if it is not a post or a page
 return;
 echo '<meta property="fb:admins" content="YOUR USER ID"/>';
 echo '<meta property="og:title" content="' . get_the_title() . '"/>';
 echo '<meta property="og:type" content="article"/>';
 echo '<meta property="og:url" content="' . get_permalink() . '"/>';
 echo '<meta property="og:site_name" content="'.get_bloginfo('name').'"/>';
 if(!LapakInstan_Function::smart_meta($post->ID, 'my_meta_image_1')) { //the post does not have featured image, use a default image
 $default_image= get_bloginfo('template_url')."/images/noimage.gif"; //replace this with a default image on your server or an image in your media library
 echo '<meta property="og:image" content="' . $default_image . '"/>';
 }else{
 //$thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'medium' );
 echo '<meta property="og:image" content="' . LapakInstan_Function::smart_meta($post->ID, 'my_meta_image_1') . '"/>';
 }
 echo "";
 }
 add_action( 'wp_head', 'insert_fb_in_head', 5 );

dan untuk v7 ke bawah gunakan kode ini :

function add_opengraph_doctype( $output ) {
 return $output . ' xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"';
 }
 add_filter('language_attributes', 'add_opengraph_doctype');
//Lets add Open Graph Meta Info
 function insert_fb_in_head() {
 global $post;
 if ( !is_singular()) //if it is not a post or a page
 return;
 echo '<meta property="fb:admins" content="YOUR USER ID"/>';
 echo '<meta property="og:title" content="' . get_the_title() . '"/>';
 echo '<meta property="og:type" content="article"/>';
 echo '<meta property="og:url" content="' . get_permalink() . '"/>';
 echo '<meta property="og:site_name" content="'.get_bloginfo('name').'"/>';
 if(!smart_meta($post->ID, 'my_meta_image_1')) { //the post does not have featured image, use a default image
 $default_image= get_bloginfo('template_url')."/images/noimage.gif"; //replace this with a default image on your server or an image in your media library
 echo '<meta property="og:image" content="' . $default_image . '"/>';
 }
 else{
 //$thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'medium' );
 echo '<meta property="og:image" content="' . smart_meta($post->ID, 'my_meta_image_1') . '"/>';
 }
 echo "
 ";
 }
 add_action( 'wp_head', 'insert_fb_in_head', 5 );

Jovan Ferryal

I would love to change the world, but they won’t give me the source code.

Related Posts

0 Comments

Submit a Comment

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *

Chat sekarang
1
Halo 👋
Ada yang bisa dibantu?