页眉&页脚代码

描述

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

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.

Since version 1.2.5 you can also define Category specific code on each individual category.
Other taxonomies (tag and custom taxonomy) do not have their specific code. Global code uses instead for them.

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
  • Lite Analytics
  • Facebook Pixel
  • Hotjar
  • FullStory
  • Google site verification
  • Bing site verification
  • Yandex site verification
  • Alexa site verification

Works or broken?

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.

Features

  • 为页眉页面部分设置站点范围的自定义内容(在</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
  • [NEW in 1.3.1] Toggle homepage specific custom code on paged Homepage in Blog Posts mode (page 2, 3, a nd so on)
  • 为页眉页面部分设置文章特定的自定义代码(在</head>之前)
  • Set article specific custom code for body section (after the <body>) – Requires WordPress 5.2!
  • 为页脚页面部分设置文章特定的自定义内容(在</body>之前)
  • [NEW in 1.3.0] Set category specific custom code for head, body and/or footer of the page
  • 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.2 compatible!

Data stored in database

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.
Each category specific HEAD, BODY and FOOTER code and behaviour saves to taxonomy meta _auhfc.

During the Uninstall process all these data has been deleted from the database.
In case you wish to reinstall plugin, DO NOT UNINSTALL IT although Deactivate, then delete the directory /wp-content/plugins-head-footer-code and then reinstall plugin.

Permissions on Multisite WordPress

Feature
Super Admin
Administrator
Editor
Author
Contributor
Subscriber

Global
Y
Y
N
N
N
N

Article specific
Y
Y
Y
Y
N
N

Category specific
Y
Y
N
N
N
N

屏幕截图

  • 在插件搜索结果中的页眉 & 页脚代码框
  • Plugin Settings page (Site-wide, Homepage and Article Post Types)
  • 文章具体metabox(Article specific metabox)
  • 插入HEAD(页眉)部分的自定义代码示例(站点范围内附加了特定文章)
  • Example of custom code inserted to BODY and FOOTER sections (site-wide with appended article specific)
  • Category specific metabox
  • Example of custom code inserted to HEAD section (site-wide with appended category specific)
  • Example of custom code inserted to BODY and FOOTER section (site-wide with appended category specific)
  • 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.

Standard procedure

  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 procedure

  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.

常见问题

On Network WordPress an Administrator/Editor/Author user getting code validation hint error `Tag is not allowed.`

It’s not a bug, it’s a security measure by WordPress Core.

If you wish to remove hinting errors for Administrator role, make sure you allow unfiltered_html capability for that role (Google is your friend).

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();
}
`

评价

2023年3月19日 1 回复
This plugin really saves you time and hassle if you need to add some code to your theme. And even better - you can change themes and the codes will stay. There was a small issue with output logic, but Aleksandar was really helpful and updated the plugin swiftly, which meant that I don't have to waste my time on finding alternative plugin for my websites and transferring codes - so this deserves a 5*
2023年2月19日 1 回复
It's the best plugin to come along. It allows me to display a site-wide Creative Common license and still drop-in other licenses and copyright for guest posts, pages and published works not part of my site-wide license.
2022年8月3日
Thanks for such a great plugin that just works.
阅读所有42条评价

贡献者及开发者

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

贡献者

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

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

对开发感兴趣吗?

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

更新日志

1.3.2 (2023-06-02)

  • Tested: on PHP 8.2.6 and WordPress 6.2.2 with Twenty Twenty-Three theme (Single and Multisite)
  • Fixed: Deprecated and Warning notices in update.php on PHP 8.2.6
  • Improve: Multisite support CodeMirror on Article and Category

1.3.1 (2023-03-18)

  • Tested: on PHP 8.1.14/8.2.1 and WordPress 6.2-RC2 with Twenty Twenty-Three theme (Single and Multisite)
  • Add: support do not add homepage in Blog Post related code on paged pages (2, 3, and so on)
  • Add: CodeEditor on textareas in article Meta boxes
  • Fix: Fatal error due to relocated plugin update file
  • Cleanup: Remove donate button from settings page
  • Improve: Security.
  • Improve: Coding Standard.

1.3.0 (2022-05-08)

  • Tested: on PHP 8.1.5 and WordPress 6.0-RC1 with Twenty Twenty-Two theme (Single and Multisite)
  • Add: Support for Categotry specific code.
  • Improve: Coding Standard.
  • Improve: Important notes on settings page.
  • Improve: README converted to MarkDown.
  • Improve: Remove PayPal logo and load minified admin stylesheet.

1.2.4 (2021-10-15)

  • Tested: on WordPress 5.8.1 and PHP 8.0.9 and 8.0.11
  • Improve: clarify within article metabox on how replace behaviour for article-specific code works
  • (2021-08-23) Improve: along to FOOTER, enable processing of shortcodes in HEAD and BODY (you has to enable this opetion per location)

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

  • 初始发行。