所以我正在制作一个使用自定义字段的插件。
现在我已经保存了字段并且除了最后一部分之外一切正常,我无法回显以在头部显示单词字符串作为html。一切都正确显示,但$ keywords为空。
我尝试过使用全局变量和静态变量但效果相同。
function PrintKeywords( $post ){
$keywords = get_post_meta( $post->ID, '_my_meta_value_key2', true );
echo '<meta name="keywords" content="' . $keywords . '" />';
}
add_action( 'wp_head', 'PrintKeywords' );
答案 0 :(得分:0)
在您的函数中放置global $post
:
function PrintKeywords( $post ){
global $post;
$keywords = get_post_meta( $post->ID, '_my_meta_value_key2', true );
echo '<meta name="keywords" content="' . $keywords . '" />';
}