Created
March 31, 2012 13:06
-
-
Save TAKAyukiatkwsk/2264002 to your computer and use it in GitHub Desktop.
WordPressサイトのOGP設定
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 | |
function my_blog_description() { | |
$description = ''; | |
if ( is_single() ) { | |
// 投稿の場合 | |
$_post = get_post(); | |
$description = $_post->post_content; | |
$description = preg_replace( "/[\n|\r|\n\r|\t|\s]/", '', $description ); | |
$description = strip_tags( $description ); | |
$more_str = mb_strlen( $description, 'UTF-8' ) > 100 ? '...' : ''; | |
$description = htmlspecialchars( mb_substr( $description, 0, 100, 'UTF-8' ) . $more_str ); | |
} else { | |
$description = bloginfo( 'description' ); | |
} | |
return $description; | |
} |
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> | |
<head> | |
<?php | |
global $page, $paged; | |
$title = wp_title( '|', false, 'right' ); | |
// Add the blog name. | |
$title .= get_bloginfo( 'name' ); | |
// Add a page number if necessary: | |
if ( $paged >= 2 || $page >= 2 ) | |
$title .= ' | ' . sprintf( __( 'Page %s', 'twentyeleven' ), max( $paged, $page ) ); | |
?><title><?php echo $title; ?></title> | |
<meta property="og:title" content="<?php echo $title; ?>" /> | |
<meta property="og:type" content="<?php echo is_home() ? 'blog' : 'article'; ?>" /> | |
<meta property="og:url" content="<?php echo 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>" /> | |
<meta property="og:site_name" content="<?php bloginfo( 'name' ); ?>" /> | |
<meta property="fb:admins" content="" /><!-- facebook IDを設定する --> | |
<meta property="og:description" content="<?php echo my_blog_description(); ?>" /> | |
</head> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment