Facebook Open Graph settings for a share posts!
Last active
January 1, 2016 17:49
-
-
Save vicainelli/8179624 to your computer and use it in GitHub Desktop.
WordPress Facebook Open Graph
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Facebook Open Graph settings | |
// og:type | |
function og_type() { | |
if (is_home() || is_page() || is_search()){ | |
echo "website"; | |
}else{ | |
echo "article"; | |
} | |
} | |
// og:url | |
function og_url() { | |
if (is_home()) { | |
echo esc_url( home_url( '/' ) ); | |
}else{ | |
echo get_permalink($post->ID); | |
} | |
} | |
// og:image | |
function og_image() { | |
if (is_home() || is_page()) { | |
bloginfo('template_url');echo '/images/facebook-share.jpg'; | |
}else{ | |
if (has_post_thumbnail()) { | |
$url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); | |
echo $url; | |
}else{ | |
bloginfo('template_url');echo '/images/facebook-share.jpg'; | |
} | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html lang="pt-BR"> | |
<head> | |
<!-- Open Graph --> | |
<meta property="og:title" content="<?php wp_title('|',true,'right'); ?><?php bloginfo('name'); ?>" /> | |
<meta property="og:type" content="<?php og_type(); ?>"/> | |
<meta property="og:url" content="<?php og_url(); ?>"/> | |
<meta property="og:image" content="<?php og_image(); ?>" /> | |
<meta property="og:site_name" content="<?php bloginfo('name'); ?>"/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment