Meta Tags by Meta Box

时间:2014-05-05 作者:Chris

我已经成功地将自定义元标记添加到我页面上的元框中。我遇到的问题是,当metabox没有数据时,它仍然显示在html中。这是我得到的代码,有人对如何不显示这一点有什么想法吗?

    <!-- Google Meta Tags -->
<meta name="citation_title" content="<?php if(get_post_meta($post->ID, "vw_citation_title", true) !=\'\' ) echo get_post_meta($post->ID, "vw_citation_title", true);?>">
<meta name="citation_author" content="<?php if(get_post_meta($post->ID, "vw_citation_author", true) !=\'\' ) echo get_post_meta($post->ID, "vw_citation_author", true);?>">
<meta name="citation_author" content="<?php if(get_post_meta($post->ID, "vw_citation_author_1", true) !=\'\' ) echo get_post_meta($post->ID, "vw_citation_author_1", true);?>">
<meta name="citation_author" content="<?php if(get_post_meta($post->ID, "vw_citation_author_2", true) !=\'\' ) echo get_post_meta($post->ID, "vw_citation_author_2", true);?>">
<meta name="citation_author" content="<?php if(get_post_meta($post->ID, "vw_citation_author_3", true) !=\'\' ) echo get_post_meta($post->ID, "vw_citation_author_3", true);?>">
<meta name="citation_author" content="<?php if(get_post_meta($post->ID, "vw_citation_author_4", true) !=\'\' ) echo get_post_meta($post->ID, "vw_citation_author_4", true);?>">
<meta name="citation_author" content="<?php if(get_post_meta($post->ID, "vw_citation_author_5", true) !=\'\' ) echo get_post_meta($post->ID, "vw_citation_author_5", true);?>">
<meta name="citation_author" content="<?php if(get_post_meta($post->ID, "vw_citation_author_6", true) !=\'\' ) echo get_post_meta($post->ID, "vw_citation_author_6", true);?>">
<meta name="citation_author" content="<?php if(get_post_meta($post->ID, "vw_citation_author_7", true) !=\'\' ) echo get_post_meta($post->ID, "vw_citation_author_7", true);?>">
<meta name="citation_author" content="<?php if(get_post_meta($post->ID, "vw_citation_author_8", true) !=\'\' ) echo get_post_meta($post->ID, "vw_citation_author_8", true);?>">
<meta name="citation_author" content="<?php if(get_post_meta($post->ID, "vw_citation_author_9", true) !=\'\' ) echo get_post_meta($post->ID, "vw_citation_author_9", true);?>">
<meta name="citation_publication_date" content="<?php if(get_post_meta($post->ID, "vw_citation_publication_date", true) !=\'\' ) echo get_post_meta($post->ID, "vw_citation_publication_date", true);?>">
<meta name="citation_journal_title" content="<?php if(get_post_meta($post->ID, "vw_citation_journal_title", true) !=\'\' ) echo get_post_meta($post->ID, "vw_citation_journal_title", true);?>">
<meta name="citation_volume" content="<?php if(get_post_meta($post->ID, "vw_citation_volume", true) !=\'\' ) echo get_post_meta($post->ID, "vw_citation_volume", true);?>">
<meta name="citation_issue" content="<?php if(get_post_meta($post->ID, "vw_citation_issue", true) !=\'\' ) echo get_post_meta($post->ID, "vw_citation_issue", true);?>">
<meta name="citation_firstpage" content="<?php if(get_post_meta($post->ID, "vw_citation_first_page", true) !=\'\' ) echo get_post_meta($post->ID, "vw_citation_first_page", true);?>">
<meta name="citation_lastpage" content="<?php if(get_post_meta($post->ID, "vw_citation_last_page", true) !=\'\' ) echo get_post_meta($post->ID, "vw_citation_last_page", true);?>">
<meta name="citation_pdf_url" content="<?php if(get_post_meta($post->ID, "vw_citation_pdf_url", true) !=\'\' ) echo get_post_meta($post->ID, "vw_citation_pdf_url", true);?>">

1 个回复
SO网友:s_ha_dum

这实际上只是一个PHP问题,但由于没有核心函数来实现这一点。。。

我会用!empty(). 否则只是echo 字符串。

$mcontent = get_post_meta($post->ID, "vw_citation_title", true);
if(!empty($mcontent)) {
    echo \'<meta name = "citation_title" content = "\'\'.$mcontent.\'" >\';
}

结束

相关推荐

删除由另一个插件-WooCommerce注册的Metabox

我正在尝试删除WooCommerce添加的gallery metabox-它已在更新中添加,但我已经有了gallery metabox,我不想混淆客户端。显然,我可以破解插件,但我想从功能上做到这一点。php我尝试过:function remove_my_meta_boxes() { remove_meta_box( \'woocommerce-product-images\', \'product\', \'side\'); } add_action( \'admin_