我想你可以做以下之一:
1-手動放置元標記頭:
<meta property="fb:admins" content="XXXXXXX"/>
<meta property="og:site_name" content="Example.com"/>
<meta property="og:image" content="http://www.example.com/image.png"/>
<?php if (is_front_page()) : ?>
<meta property="og:type" content="blog"/>
<meta property="og:description" content="test test test test"/>
<meta property="og:title" content="My title"/>
<meta property="og:url" content="<?php echo get_bloginfo('home'); ?>"/>
<?php elseif (is_single() || is_page()) : ?>
<meta property="og:type" content="article"/>
<meta property="og:title" content="<?php echo trim(wp_title('', false)); ?>"/>
<meta property="og:url" content="<?php echo get_permalink(); ?>"/>
<?php elseif (!is_front_page() && !is_single() && !is_page()) : ?>
<meta property="og:title" content="<?php echo trim(wp_title('', false)); ?>"/>
<?php endif ?>
或者,如果你想使用掛鉤(的functions.php):
add_action('wp_head', 'add_og_meta_tags');
function add_og_meta_tags() {
echo '<meta property="fb:admins" content="XXXXXXX"/>
<meta property="og:site_name" content="Example.com"/>
<meta property="og:image" content="http://www.example.com/image.png"/>';
if (is_front_page()) :
echo '<meta property="og:type" content="blog"/>
<meta property="og:description" content="test test test test"/>
<meta property="og:title" content="My title"/>
<meta property="og:url" content=" '. get_bloginfo('home') . '"/>';
elseif (is_single() || is_page()) :
echo '<meta property="og:type" content="article"/>
<meta property="og:title" content="' . trim(wp_title('', false)) . '"/>
<meta property="og:url" content="' . get_permalink() .'"/>';
elseif (!is_front_page() && !is_single() && !is_page()) :
echo '<meta property="og:title" content="' . trim(wp_title('', false)) .'"/>';
endif;
}
是的,謝謝!我選擇了functions.php中的鉤子,並且工作出色。 – waffl 2011-05-09 23:00:20