页眉&页脚代码

描述

页眉&页脚代码 plugin helps you add custom code snippets (JavaScript, CSS, or HTML) to the page even if you are not a programmer. It could be <head> (site verification code for various services, custom styles, meta or Webfont link), just before </body> or right after opening <body> (pixel tracking, analytics or heatmap code).

Go to Tools页眉&页脚代码 in WordPress Dashboard. Insert custom code to HEAD, BODY or FOOTER section (depending on what you have to do).

If your WordPress shows the latest blog posts on the homepage, you can also add specific code only for the homepage on Tools页眉&页脚代码 (there will be section Head, body and footer code on Homepage in Blog Posts mode)

To insert custom code specific for individual article (post, page or custom post type), use article-specific Metabox while editing post/page/custom post type (check out Screenshots). There choose if that specific code appends to site-wide code defined on Tools页眉&页脚代码, or to replace it.

Taxonomies (category, tag and custom taxonomy listing, individual category, tags and custom taxonomies) do not have their specific code. Global code uses instead.

This magic is done by hooking to WordPress hooks wp_head, wp_footer and wp_body_open.

Various code snippets are supported, including but not limited to:

  • Google Analytics
  • Google Tag Manager
  • Google Ads Conversion
  • Facebook Pixel
  • Hotjar
  • FullStory
  • Google site verification
  • Bing site verification
  • Yandex site verification
  • Alexa site verification

插件完美或者插件出错

If 页眉&页脚代码 does not work on your WordPress project, please let us know by raising a new support ticket in the Community Forum and describe what does not works and how to reproduce the issue. We will make sure to resolve the issue as soon as possible.

If you find 页眉&页脚代码 useful for your project, please review plugin.

特点

  • 为页眉页面部分设置站点范围的自定义内容(在</head>之前)
  • Set site-wide custom content for body section (after the <body>) – Requires WordPress 5.2!
  • 为页脚页面部分设置站点范围的自定义内容(在</body>之前)
  • [NEW in 1.2] Set homepage specific custom code for head, body and/or footer if Homepage mode is se to Blog Posts
  • 为页眉页面部分设置文章特定的自定义代码(在</head>之前)
  • Set article specific custom code for body section (after the <body>) – Requires WordPress 5.2!
  • 为页脚页面部分设置文章特定的自定义内容(在</body>之前)
  • Choose priority of printed custom code to head/body/footer sections (lower number mean far from </head> and </body> and closer to <body>, higher number means closer to </head> and </body> and farther to <body>)
  • Choose which post types will have enabled article specific head/body/footer fields
  • Choose should article specific head/body/footer code be appended to site-wide code, or will replace site-wide code
  • [NEW in 1.2.1] View on Posts/Pages/Custom Post Types listing if article has defined any article specific custom code
  • 位于工具>下的网站范围部分 页眉 & 页脚代码
  • 并未翻译:If you have set WP_DEBUG constant in wp-config.php to true, you’ll see site-wide and article specific entries in page source code wrapped to comments.
  • Multisite is supported.
  • PHP 8 ready!

General settings (HEAD, BODY, FOOTER global code and priority, Homepage code and behaviour) saves in WordPress option auhfc_settings.
Each post/page/custom post type specific HEAD, BODY and FOOTER code and behaviour saves to post meta _auhfc.
This data deletes from the database on uninstall.

屏幕截图

  • 在插件搜索结果中的页眉 & 页脚代码框
  • Plugin Settings page (Site-wide, Homepage and Article Post Types)
  • 文章具体metabox(Article specific metabox)
  • 插入HEAD(页眉)部分的自定义代码示例(站点范围内附加了特定文章)
  • Example of custom code inserted to BODY section (site-wide with appended article specific)
  • 插入FOOTER(页脚)部分的自定义代码示例(站点范围内附加了特定文章)
  • Example of 页眉&页脚代码 column on Pages listing, to identify which pages have set custom code, which one and what mode is selected

安装

Installation of the 页眉&页脚代码 is easy as any other WordPress plugin.

标准程序

  1. In WordPress Dashboard go to PluginsAdd New.
  2. Enter head footer code to the Search plugins… field and wait for the moment.
  3. Locate 页眉&页脚代码 and click the Install Now button.
  4. After successful installation, click the Activate button.
  5. Click Settings link for 页眉&页脚代码 or visit the Tools页眉&页脚代码.
  6. Add the desired code to the target section.

FTP 程序

  1. Click on the Download button to get 页眉&页脚代码 installation package.
  2. Unpack archive head-footer-code.zip on local computer.
  3. Upload the entire directory head-footer-code to the /wp-content/plugins/ directory on your server.
  4. In WordPress Dashboard go to PluginsInstalled Plugins and click the link Activate for the 页眉&页脚代码 plugin.
  5. Click Settings link for 页眉&页脚代码 or visit the Tools页眉&页脚代码.
  6. Add the desired code to the target section.

常见问题

Is supported PHP code in code snippets?

As it’s a security risk, the 页眉&页脚代码 does not process PHP code if entered into any plugin field (global or article specific).

Any content added to HFC fields is printed on the front-end as is.

I entered code to BODY section, but nothing outputs on front-end

This feature is implemented since WordPress version 5.2 and requires theme compatibility.

To make sure if theme you use supports wp_body_open hook, open in code editor header.php file from theme you use, and check if right after opening <BODY> tag there is following code (if it does not exists, add it or ask some developer to do that for you):

`

if ( function_exists( ‘wp_body_open’ ) ) {
wp_body_open();
}
`

评价

2021年6月15日
This plugin is what exactly I'm looking for to add custom javascript and CSS codes to specific pages without inserting them inside the template.
2021年2月27日
A perfect solution when you want to add custom scripts or codes to the header, body, or footer without touching the theme files. Working well to our needs and the support is quick to assist when you experience any issues.
阅读所有30条评价

贡献者及开发者

“页眉&页脚代码” 是开源软件。 以下人员对此插件做出了贡献。

贡献者

“页眉&页脚代码”插件已被翻译至5种本地话语言。 感谢所有译者为本插件所做的贡献。

将“页眉&页脚代码”翻译成您的语言。

对开发感兴趣吗?

您可以浏览代码,查看SVN仓库,或通过RSS订阅开发日志

更新日志

1.2.3 (2021-07-19)

  • Tested: on WordPress 5.8-RC4 and PHP 8.0.8
  • (2021-05-04) Fix: Notice errors Trying to get property ‘post_type’ of non-object in inc/front.php (thanks to @tekgirlymama)
  • Improve: DRY for getting post type.

1.2.2 (2021-04-24)

  • Tested: on WordPress 5.7.1
  • (2021-02-01) Fix: Noice errors in update script (thanks to @swinggraphics)
  • Improve: wording on post/page listing

1.2.1

  • Add: Head & Footer Code column to post/page/custom post type listing to show if/what article specific custom code is defined
  • Fix: in_array() expects parameter 2 to be array, null given in head-footer-code/inc/front.php on line 46, 111, and 176

1.2

  • Add: custom head, body and footer code for Homepage in Blog Posts mode.
  • Fix: Code Editor broken in WordPress 5.5 release.
  • Fix: Invalid requests while saving settings https://github.com/urosevic/head-footer-code/issues/1
  • Improve: DRY for front-end conditions.
  • Improve: translators tips for complex strings.
  • Improve: all strings available to localize.

1.1.1

  • Tested: on WordPress 5.4.1, 5.5-RC2-48768 with PHP 7.4.1
  • Add: Video tutorial on how to install, configure and use Head & Footer Code plugin

1.1.0

  • Tested: on WordPress 5.1.4, 5.3.2 and 5.4-beta3 with PHP 7.2.15 and 7.3.7
  • Fix: Backslashes are removed on post/page update in article specific HEAD/BODY/FOOTER code reported by @asherber (update_post_meta pass key and value to update_metadata which expect them slashed key and value)
  • Add: Support for wp_body_open Body hook introduced in WordPress 5.2
  • Add: Backward compatibility for wp_body_open for older WordPress installations
  • Add: FAQ Instructions on how to implement support for wp_body_open to any theme
  • Update: Links and wording on plugin settings page
  • 更新:截图

1.0.9.1

  • 修复:多站点WP的致命错误(感谢@kunzemarketing报告)
  • 改进:用于前端调试的DRI

1.0.9

  • 添加:特定于文章的部分的描述性帖子类型和描述
  • 添加:在FOOTER部分处理短代码的选项(站点范围和特定于文章的全局设置)
  • 更改:HEAD和FOOT的独立优先级,以便管理员可以为页眉和页脚选择不同的优先级
  • 在插件设置中添加:用于HEAD和FOOTER代码的CodeMirror代码编辑器
  • 添加:插件激活挂钩,以防止传统WP和/或PHP的致命错误
  • 改进:加载安全性

1.0.8

  • 测试与WordPress 5.1.1和PHP 7.2.15的兼容性
  • 更改:元框布局和行为选择器的类型
  • 更改:将Post元变换转换为OOP
  • 更改:GNU GPL许可证到v3
  • 添加:捆绑GNU GPLv3许可证到插件代码库
  • 更新:截图

1.0.7

  • 兼容性检查:针对WordPress 4.7.1进行了测试
  • 用户体验:在全局设置页面上添加右侧边栏,其中包含捐赠链接,常见问题解答,社区支持和插件评论页面。
  • UX:在全局设置和文章页面上为textareas设置等宽字体

1.0.6

  • 修复: PHP注意:尝试获取非对象的属性在\wp-content\plugins\head-footer-code\inc\front.php中第41行
  • 修复:如果内容之后的文章/页面模板有另一个WP循环查询(如最近在RHS侧栏中发布的WP Widget),则覆盖文章/页面的页脚内容。
  • 优化:如果不是单数或文章类型未启用,请避免阅读文章元数据
  • 在WordPress v4.5-alpha-36504和主题Twenty Sixteen v1.2-alpha上的多站点环境(主要和其他网络网站)中进行测试。

1.0.5

  • 增强:添加卸载例程以在删除插件时进行一些内务处理。
  • 增强:在调试注释中添加文章类型。
  • 自述文件:测试WordPress v4.4-beta1并更新兼容性。

1.0.4

  • 修复:PHP警告:in_array() 期望参数2为数组,给定字符串(在v1.0.3中引入)

1.0.3

  • 更改:为特定于页面的页眉/页脚代码创建甚至默认的WP文章类型postpage可选

1.0.2

  • 更改:如果在违反PayPal可接受使用政策的网站上使用插件,则替换PayPal捐款链接以防止帐户限制

1.0.1

  • 修复:PHP注意尝试获取非对象的属性
  • 优化:从可用中删除附件文章类型,以选择无需在附件上设置自定义页眉/页脚代码
  • 优化:设置代码清理

1.0.0

  • 初始发行。