手机html模板标头代码_在HTML标头中停用WordPress内置的规范URL链接标记

手机html模板标头代码

The built-in canonical URL function since WordPress 2.9 is great. But under some situation, it is not needed. For example, all the Mingle Forum threads’ canonical URL is set to the URL of the page that contains the [mingleforum] shortcode, which, of course, is wrong.

自WordPress 2.9起内置的规范URL功能。 但是在某些情况下,它是不需要的。 例如,所有Mingle论坛线程的规范URL都设置为包含[mingleforum]短代码的页面的URL,这当然是错误的。

How to diabled it?

如何将其禁用?

We can disabled WordPress’s Built-in Canonical URL by the following script:

我们可以通过以下脚本禁用WordPress的内置规范URL:

# Remove WordPress' canonical links
remove_action('wp_head', 'rel_canonical');

Specifically for Mingle forum, we only need to disable the canonical links for pages. Here are the changes:

专门针对Mingle论坛,我们只需要禁用页面的规范链接。 更改如下:

diff --git a/b/wp-content/plugins/mingle-forum/wpf.class.php b/b/wp-content/plug
index 4e00451..96ca02c 100644
--- a/b/wp-content/plugins/mingle-forum/wpf.class.php
+++ b/b/wp-content/plugins/mingle-forum/wpf.class.php
@@ -20,6 +20,8 @@ class mingleforum{
                add_action("admin_menu", array(&$this,"add_admin_pages"));
                add_action("admin_head", array(&$this, "admin_header"));
                add_action("wp_head", array(&$this, "setup_header"));
+        # Remove WordPress' canonical links
+        remove_action('wp_head', 'rel_canonical');
                add_action("plugins_loaded", array(&$this, "wpf_load_widget"));
                add_action("wp_footer", array(&$this, "wpf_footer"));
                if($this->options['wp_posts_to_forum'])
@@ -34,7 +36,8 @@ class mingleforum{
                add_filter('mf_ad_above_info_center', array(&$this, 'mf_ad_above
                add_filter('mf_ad_above_quick_reply', array(&$this, 'mf_ad_above
                add_filter('mf_ad_above_breadcrumbs', array(&$this, 'mf_ad_above
-               add_filter('mf_ad_below_first_post', array(&$this, 'mf_ad_below_
+        add_filter('mf_ad_below_first_post', array(&$this, 'mf_ad_below_first_p
+
                $this->init();
        }

@@ -1260,7 +1263,10 @@ class mingleforum{
                        }
                        </script>
                <?php
-               }
+        }
+        else {
+            rel_canonical();
+        }
        }
Answered by anonymous.
匿名回答。


More readings about canonical URL in WordPress:

有关WordPress中规范URL的更多信息:

http://stackoverflow.com/questions/2430623/wordpress-auto-generated-canonical-links-how-to-add-a-custom-url-parameter

http://stackoverflow.com/questions/2430623/wordpress-auto-generation-canonical-links-how-to-add-a-custom-url-parameter

http://pixelpunk.co.uk/2010/01/disable-wordpress-built-in-canonical-url/

http://pixelpunk.co.uk/2010/01/disable-wordpress-built-in-canonical-url/



Hi ,

嗨,

Thank you for your recommendation for removing the canonical link for the forum page only. However, I am am not able to find the following code in the wpf.class.php and was hoping you let us know where we can find this class so that we can modify it accordingly. (Does -1260 refer to the line number in the wpf.class.php?

感谢您的建议,仅删除论坛页面的规范链接。 但是,我无法在wpf.class.php中找到以下代码,并希望您让我们知道在哪里可以找到该类,以便我们可以进行相应的修改。 (-1260是否引用wpf.class.php中的行号?

@@ -1260,7 +1263,10 @@ class mingleforum{
}

@@ -1260,7 +1263,10 @@ class mingleforum {
}

<?php
– }
+ }
+ else {
+ rel_canonical();
+ }
}

<?php
–}
+}
+其他{
+ rel_canonical();
+}
}

Google is not indexing our forum and we do not want to remove the canonical links globally cause we are not sure if it is going to cause other issues …

Google并未将我们的论坛编入索引,我们也不想在全球范围内删除规范链接,因为我们不确定它是否会导致其他问题……



Hi trueactivist,

嗨,积极分子,

The canonical URL is really a problem and possibly prevent Google from indexing your forum since the canonical tag keeps telling Google that all forum posts are the “same page”.

规范网址确实是一个问题,可能会阻止Google将您的论坛编入索引,因为规范标签不断告诉Google所有论坛帖子都是“同一页面”。

For you reference, I post more code related to the canonical URL here:

供您参考,我在这里发布了更多与规范URL相关的代码:

(The line numbers may not be the same as yours since I customized Mingle forum a lot).

(线路编号可能与您的线路编号不同,因为我对Mingle论坛进行了很多定制)。

wpf.class.php

wpf.class.php

1 <?php
   2 include("wpf_define.php");
   3 include_once( 'bbcode.php' );
   4 //@ob_start();
   5 
   6 if(!class_exists('mingleforum')){
   7 class mingleforum{
   8 
   9     var $db_version = 1; //MANAGES DB VERSION
  10 
  11     function mingleforum()
  12     {
  13         $this->get_forum_admin_ops();
  14         $this->get_set_ads_options();
  15         if($this->options['forum_use_seo_friendly_urls'])
  16         {
  17             add_filter("init", array(&$this, "flush_wp_rewrite_rules"));
  18             add_filter("rewrite_rules_array", array(&$this, "set_seo_friendly_rules"));
  19         }
  20         add_action("admin_menu", array(&$this,"add_admin_pages"));
  21         add_action("admin_head", array(&$this, "admin_header"));
  22         add_action("wp_head", array(&$this, "setup_header"));
  23         # Remove WordPress' canonical links
  24         remove_action('wp_head', 'rel_canonical');
  25         add_action("plugins_loaded", array(&$this, "wpf_load_widget"));
  26         add_action("wp_footer", array(&$this, "wpf_footer"));

Here, line 23, 24 is newly added to remove canonical tag.

此处,新添加了第23、24行以删除规范标签。

wpf.class.php

wpf.class.php

1292     function setup_header(){
1293         $this->setup_links();
1294         global $user_ID;
1295         if(is_page($this->get_pageid()))
1296         {
1297             if($this->options['forum_use_rss']) { ?>
1298                 <link rel='alternate' type='application/rss+xml' title="<?php echo __("Forums RSS", "mingleforum"); ?>" href="<?php echo $this->global_feed_url;?>" /> <?php
1299             }
1300             if($this->ads_options['mf_ad_custom_css'] != "") {
1301             ?>
1302             <style type="text/css"><?php echo stripslashes($this->ads_options['mf_ad_custom_css']); ?></style>
1303             <?php } //ENDIF FOR CUSTOM ADS CSS ?>
1304             <link rel='stylesheet' type='text/css' href="<?php echo "$this->skin_url/style.css";?>"  />
1305             <script language="JavaScript" type="text/javascript" src="<?php echo WPFURL."js/script.js"?>"></script>
1306             <script language="JavaScript" type="text/javascript">
1307             function wpf_confirm(){
1308                 var answer = confirm ('<?php echo __("Are you sure you want to remove this?", "mingleforum");?>');
1309                 if (!answer)
1310                     return false;
1311                 else
1312                     return true;
1313             }
1314             </script>
1315 
1316             <?php $this->generate_canonical_tag(); // add cononical tag ?>
1317 
1318         <?php
1319         }
1320         else {
1321             rel_canonical();
1322         }
1323     }

This is the changed setup_header() function. The idea is to enable canonical tag again for non-page in WordPress, and add canonical tag for the page for Mingle forum. For other pages, just ignore the canonical tag—this should be find if your site uses WordPress posts with not that many pages.

这是更改后的setup_header()函数。 这个想法是为WordPress中的非页面再次启用规范标记,并为Mingle论坛的页面添加规范标记。 对于其他页面,只需忽略规范标记-如果您的站点使用的WordPress帖子页面不多,则应该找到该标记。

The generate_canonical_tag() function is as follows (if it is not provided by Mingle forum. I can not remember it clearly).

generate_canonical_tag()函数如下(如果Mingle论坛未提供该函数。我记不清楚了)。

1262     function generate_canonical_tag()
1263     {
1264         $url = '';
1265         if ($this->options['forum_use_seo_friendly_urls'])
1266         {
1267             $uri = $this->get_seo_friendly_query();
1268             if (!empty($uri) && $uri['action'] && $uri['id'])
1269             {
1270                 switch($uri['action'])
1271                 {
1272                 case 'group':
1273                     $url = $this->get_grouplink($uri['id']);
1274                     break;
1275                 case 'forum':
1276                     $url = $this->get_forumlink($uri['id']);
1277                     break;
1278                 case 'thread':
1279                     $url = $this->get_threadlink($uri['id']);
1280                     break;
1281                 }
1282             }
1283         }
1284         if (!empty($url)) {
1285             echo "<link rel='canonical' href='" . $url . "' />";
1286         }
1287         // echo " " . $uri['id'] . " ";
1288         return true;
1289     }

翻译自: https://www.systutorials.com/disable-wordpress-built-in-canonical-url-link-tag-in-html-head/

手机html模板标头代码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值