尝试将以下代码复制到函数中。php文件。
它为具有以下名称的作者添加了自定义og:image属性michelle-robinson
, mystery-man
, john-smith
, 和默认回退映像。您可以轻松更改此选项以满足您的需要。
add_action( \'wp_head\', \'wpse_70701_author_image\' );
function wpse_70701_author_image() {
if ( is_author( \'michelle-robinson\' ) ) {
// set a custom image if we\'re visiting Michelle Robinson\'s author page
echo \'<meta property="og:image" content="http://www.phoneographer.org/wp-content/uploads/link-to-michelle-robinson-image.png" />\';
}
elseif ( is_author( \'mystery-man\' ) ) {
// set a custom image if we\'re visiting Mystery Man\'s author page
echo \'<meta property="og:image" content="http://www.phoneographer.org/wp-content/uploads/link-to-mystery-man-image.png" />\';
}
elseif ( is_author( \'john-smith\' ) ) {
// set a custom image if we\'re visiting John Smith\'s author page
echo \'<meta property="og:image" content="http://www.phoneographer.org/wp-content/uploads/link-to-mystery-man-image.png" />\';
}
else {
// set the default fallback image (you may want to omit this section)
echo \'<meta property="og:image" content="http://www.phoneographer.org/wp-content/uploads/link-to-author-image.png" />\';
}
}
在这里,我给了函数一个唯一的名称,但您可以根据需要调用该函数,只要它不是另一个函数的名称。如果重命名函数,还需要编辑
add_action
钩