【问题标题】:How to change HTML structure inside WP <head>如何更改 WP <head> 中的 HTML 结构
【发布时间】:2013-09-24 18:23:43
【问题描述】:

我正在清理一些 HTML 代码,我想要一个看起来像这样的 HTML 结构:

<!DOCTYPE html>
<html >
<head>
<title>...</title>
<meta name="description" content="..." />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> ...

所以基本上我希望“标题”和“元描述”出现在“头”标签之后。 网站正在运行 Wordpress,所以我已经查看了 general-template.php -file,但没有找到“元描述”的输出。

我是否需要安装一个用于元描述的插件(例如 Yoast),然后更改 wp_head() 的位置?还是我需要以某种方式编辑 wp_head() 函数?

【问题讨论】:

  • 可能是 SEO 信徒认为如果内容不是特定顺序,搜索引擎机器人无法阅读。你在这上面浪费时间吗?检查主题文件夹中的 header.php。

标签: php html wordpress xhtml html-head


【解决方案1】:

编辑你的主题 header.php,简单 :) 确保 &lt;?php wp_head();?&gt; 在所有这些之下(如果存在)...

【讨论】:

    【解决方案2】:

    只要确保&lt;?php wp_head();?&gt; 位于您的头部标签之间。这样,当您安装 Yoast SEO 或任何插件时,它就能够插入正确的内容。

    【讨论】:

      【解决方案3】:

      有很多清洁头解决方案,例如添加钩子来清洁大多数 worpress 默认功能(RSD、RSS 链接等)。在主题functions.php中尝试以下钩子:

      /*remove actions to clean wp_head*/
      remove_action('wp_head', 'wlwmanifest_link'); // remove wlwmanifest.xml (needed to support windows live writer)
      remove_action('wp_head', 'wp_generator'); // remove wordpress version
      remove_action( 'wp_head', 'wp_resource_hints', 2 );//remove dns prefech
      remove_action('wp_head', 'rsd_link'); // remove really simple discovery link
      remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0 ); // remove shortlink
      
      remove_action( 'wp_head', 'print_emoji_detection_script', 7 );  // remove emojis
      remove_action( 'wp_print_styles', 'print_emoji_styles' );   // remove emojis
      
      remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); // remove the / and previous post links
      
      remove_action('wp_head', 'feed_links', 2); // remove rss feed links
      remove_action('wp_head', 'feed_links_extra', 3); // removes all extra rss feed links
      
      remove_action( 'wp_head', 'rest_output_link_wp_head', 10 ); // remove the REST API link
      remove_action( 'wp_head', 'wp_oembed_add_discovery_links' ); // remove oEmbed discovery links
      remove_action( 'template_redirect', 'rest_output_link_header', 11, 0 ); // remove the REST API link from HTTP Headers
      
      remove_action( 'wp_head', 'wp_oembed_add_host_js' ); // remove oEmbed-specific javascript from front-end / back-end
      
      remove_action('rest_api_init', 'wp_oembed_register_route'); // remove the oEmbed REST API route
      remove_filter('oembed_dataparse', 'wp_filter_oembed_result', 10); // don't filter oEmbed results
      

      您也可以将此 sn-p 包装到函数中以使其工作 after_theme_setupinit

      charsethttp-equiv 属性等其他标签可以插入 wp_head() 之后; header.php 中的操作。还可以查看 wp-includes 模板文件夹文件以找到 wp_head() 操作并删除/注释不必要的操作

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-01-07
        • 2022-11-21
        • 1970-01-01
        • 2020-10-10
        • 1970-01-01
        • 1970-01-01
        • 2022-08-23
        相关资源
        最近更新 更多