如何在WP中更改HTML结构

时间:2013-09-19 15:14:34

标签: php html wordpress xhtml html-head

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

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

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

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

3 个答案:

答案 0 :(得分:0)

编辑主题header.php,简单:)确保<?php wp_head();?>位于所有内容之下(如果它存在...)

答案 1 :(得分:0)

只需确保{head}标记之间有<?php wp_head();?>。这样当你安装Yoast SEO或任何插件时,它就能插入正确的东西。

答案 2 :(得分:0)

有许多清洁头解决方案,如添加钩子,以清理大部分的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

您也可以将此代码段包装到函数中以使其正常工作after_theme_setupinit

在wp_head()之后,可以包含charsethttp-equiv属性等其他标记。 header.php中的动作。另请查看wp-includes模板文件夹文件以查找wp_head()操作并删除/注释不必要的操作