2015-10-05 58 views
-1

我想在Google代碼片段中隱藏日期,並且我目前使用Yoast SEO插件。我不能在那裏改變,所以我想我可以自己改變它 。我注意到你在整個 7檔9場比賽的「the_date」功能。不過,我想我可以使用Javascript而不是PHP。如何使用PHP在Google代碼片段中隱藏日期?

<?php the_time('F jS, Y') ?> 

我可以代替,

<script language="javascript" 
type="text/javascript">document.write("<?php the_time('F jS, Y') 
?>");</script> 

的描述中提取數據時,谷歌不使用JavaScript。 所以它會顯示給用戶,但不會被Google讀取。

我可以在免費主題中做到這些,但無法找到所需的功能。我不知道用什麼替換什麼。

在我的文件,我只看到,

C:\wamp\www\wp-content\themes\TheDefensionem\cover.php: 
    52 // Day 
    53 if(is_day()){ 
    54: $title = get_the_date(); 
    55 $title_above = __('Daily Archives', 'brook'); 
    56 } 
    .. 
    58 // Month 
    59 if(is_month()){ 
    60: $title = get_the_date(_x('F Y', 'monthly archives date format', 'brook')); 
    61 $title_above = __('Monthly Archives', 'brook'); 
    62 } 
    .. 
    64 // Year 
    65 if(is_year()){ 
    66: $title = get_the_date(_x('Y', 'yearly archives date format', 'brook')); 
    67 $title_above = __('Yearly Archives', 'brook'); 
    68 } 

C:\wamp\www\wp-content\themes\TheDefensionem\infobar.php: 
    29    <div class="meta--items fl"> 
    30     <div class="meta--item meta--date"> 
    31:      <?php echo get_the_date(); ?> 
    32     </div> 
    33    </div> 

C:\wamp\www\wp-content\themes\TheDefensionem\loop_item-grid_gallery.php: 
    84    <div class="meta--items"> 
    85     <div class="meta--item meta--date"> 
    86:      <?php echo get_the_date(); ?> 
    87     </div> 
    88 

C:\wamp\www\wp-content\themes\TheDefensionem\loop_item-list_archive.php: 
    66 
    67    <div class="meta--item meta--date"> 
    68:     <?php echo get_the_date(); ?> 
    69    </div> 
    70 

C:\wamp\www\wp-content\themes\TheDefensionem\loop_item-widget_list.php: 
    19 
    20   <div class="meta--item meta--date"> 
    21:    <?php echo get_the_date(); ?> 
    22   </div> 
    23 

C:\wamp\www\wp-content\themes\TheDefensionem\post_meta.php: 
    2 
    3 <div class="meta--item meta--date"> 
    4:  <?php echo get_the_date(); ?> 
    5 </div> 
    6 

C:\wamp\www\wp-content\themes\TheDefensionem\related_posts.php: 
    59 
    60    <div class="meta--item meta--date"> 
    61:     <?php echo get_the_date(); ?> 
    62    </div> 
    63 

9 matches across 7 files 

我該怎麼做呢?

+0

這不是你想要做的事......你想顯示日期還是不顯示? –

+0

你不能使用javascript來編寫php代碼,當你的javascript代碼執行時,頁面已經通過php解析器並離開了服務器 –

+0

隱藏日期Julio。我明白了,那麼如何在Google代碼段中隱藏日期?任何其他方式? –

回答

0

如果您不希望谷歌使用網頁上的某些數據,那麼檢測的Googlebot(爬谷歌用於獲取片段),並且不顯示信息

<?php if($_SERVER['HTTP_USER_AGENT'] != "GoogleBot"):?> 
    <div class="meta--items fl"> 
     <div class="meta--item meta--date"> 
     <?php echo get_the_date(); ?> 
     </div> 
    </div> 
<?php endif;?> 

替換爲Googlebot會任何useragent google uses爲他們的機器人

這將需要您編輯主題文件,所以這些變化可能會在更新覆蓋。