如何在WordPress中添加页眉和页脚代码(简便⽅法)
Have you ever been asked to add some code snippets to <header> or <footer> section of your WordPress website?
您是否曾经被要求向WordPress⽹站的<header>或<footer>部分添加⼀些代码段?
Often you are asked to add header and footer code in WordPress when trying to integrate with web services like , Facebook Pixel, , etc.
在尝试与 ,Facebook Pixel, 等⽹络服务集成时,通常会要求您在WordPress中添加页眉和页脚代码。
You may also come across that might ask you to add some custom CSS or to your WordPress header or footer.
您可能还会遇到 ,这些可能会要求您在WordPress的页眉或页脚中添加⼀些⾃定义CSS或 。
By default, WordPress doesn’t provide an option to insert code in your website’s header and footer. Luckily there is an easy solution for beginners.
默认情况下,WordPress不提供在⽹站的页眉和页脚中插⼊代码的选项。 幸运的是,为初学者提供了⼀个简单的解决⽅案。
In this article, we will show you how to easily add header and footer code in WordPress. The goal is to safely add the code without directly editing your WordPress theme files.
在本⽂中,我们将向您展⽰如何轻松地在WordPress中添加页眉和页脚代码。 ⽬标是安全添加代码,⽽⽆需直接编辑WordPress主题⽂件。
添加WordPress页眉和页脚代码的最佳⽅法 (The Best Way to Add WordPress Header and Footer Code)
If you want to add WordPress header and footer code, there are three possible solutions:
如果要添加WordPress页眉和页脚代码,可以使⽤以下三种解决⽅案:
1. Manually, by editing your theme’s header.php and footer.php files
通过⼿动编辑主题的header.php和footer.php⽂件
2. With your theme’s built-in header and footer code feature
具有主题的内置页眉和页脚代码功能
3. Using a plugin
使⽤插件
The first option is not beginner friendly because it requires you to add header and footer code by directly editing the header.php and footer.php files manually.
第⼀个选项不是初学者友好的,因为它要求您通过直接⼿动编辑header.php和footer.php⽂件来添加页眉和页脚代码。
Another disadvantage of using this method is that your code will be removed if you install an update to your theme.
使⽤此⽅法的另⼀个缺点是,如果您为主题安装更新,则将删除您的代码。
The second option is using your theme’s built-in feature. Some WordPress themes like and offer a built-in option for quickly adding code and scripts to your WordPress header and footer.
第⼆个选项是使⽤主题的内置功能。 ⼀些WordPress主题(例如 和提供了⼀个内置选项,可⽤于将代码和脚本快速添加到WordPress的页眉和页脚。
If you are using a theme with a built-in feature, then it seems like a safe and simple solution. However if you change your theme, then all the code snippets added to your website will be gone. This includes site verification in Google Search Console, website analytics via Google Analytics, etc.
如果您正在使⽤具有内置功能的主题,那么这似乎是⼀个安全,简单的解决⽅案。 但是,如果您更改主题,那么添加到您的⽹站的所有代码段都将消失。 这包括在Google Search Console中进⾏⽹站验
证,通过Google Analytics(分析)进⾏⽹站分析等。
This why we always recommend users to use the third option, a headers and footers plugin. This option is by far the easiest and safest method to add header and footer code in WordPress.
这就是为什么我们始终建议⽤户使⽤第三个选项(页眉和页脚插件)的原因。 到⽬前为⽌,此选项是在WordPress中添加页眉和页脚代码的最简单,最安全的⽅法。
After a lot of request from readers, our team has built a 100% free plugin to let users easily add code to the header and footer in WordPress.
在读者的⼤量要求之后,我们的团队构建了100%免费的插件,使⽤户可以轻松地将代码添加到WordPress的页眉和页脚中。
Here are some benefits of using the Insert Headers and Footers plugin:
使⽤插⼊页眉和页脚插件有⼀些好处:
1. Easy, Fast, and Organized: It lets you add codes to your site’s header and footer easily and quickly. Plus, it keeps you organized by allowing you to store all your footer and header codes in one place.
1.轻松,快速且有条理 :它使您可以轻松快捷地将代码添加到⽹站的页眉和页脚中。 另外,它允许您将所有页脚和页眉代码存储在⼀个地⽅,从⽽使您井井有条。
2. Prevents Errors: It helps prevent errors which may occur if you edit your theme files manually.
2.防⽌错误 :如果您⼿动编辑主题⽂件,则可以防⽌发⽣错误。
3. Upgrade or Change Your Theme Without any Worry: The plugin will save your header and footer code in a separate place, so you can update or change your theme without worrying about the code being erased.
3.升级或更改主题⽽⽆需担⼼ :该插件会将您的页眉和页脚代码保存在单独的位置,因此您可以更新或更改主题,⽽不必担⼼代码被删除。
With that said, let’s see how to easily add header and footer code in WordPress using Insert Headers and Footers plugin.
话虽如此,让我们看看如何使⽤插⼊页眉和页脚插件在WordPress中轻松添加页眉和页脚代码。
影⽚教学 (Video Tutorial)
If you don’t want to watch the video tutorial, then you can continue reading the text version below:wordpress主题怎么安装
如果您不想观看视频教程,则可以继续阅读以下⽂本版本:
在WordPress的页眉和页脚中添加代码 (Adding Code to Header and Footer in WordPress)
First thing you need to do is install and activate the plugin. For more details, see our step by step guide on .
您需要做的第⼀件事是安装并激活“ 插件。 有关更多详细信息,请参阅有关步指南。
Once the plugin is activated, go to Settings » Insert Headers and Footers from your admin panel. After that, you will see two boxes for adding code to header and footer.
激活插件后,从管理⾯板转到设置»插⼊页眉和页脚 。 之后,您将看到两个⽤于向页眉和页脚添加代码的框。
Simply paste the code in one of the two boxes. Once done, don’t forget to click the Save button to store your changes.
只需将代码粘贴到两个框之⼀中。 完成后,不要忘记单击“保存”按钮来存储您的更改。
The plugin will now automatically load the code in the respective locations on your WordPress site.
插件现在将⾃动在WordPress⽹站上的相应位置加载代码。
You can always edit and remove any code that you don’t want to keep.
您始终可以编辑和删除您不想保留的任何代码。
You’ll need to keep the plugin installed and activated at all times. Deactivating the plugin will stop adding all custom code to your site.
您需要始终保持插件的安装和激活状态。 停⽤插件将停⽌将所有⾃定义代码添加到您的⽹站。
If you accidentally deactivate the plugin, the code will still be safely stored in your WordPress database. You can simply reinstall or reactivate the plugin, and the code will start appearing again.
如果您不⼩⼼停⽤了该插件,该代码仍将安全地存储在WordPress数据库中。 您可以简单地重新安装或重新激活插件,该代码将再次开始出现。
Note: You may have to after saving changes, so the code properly appears on the front-end of your website.
注意:保存更改后,您可能必须 ,因此代码正确显⽰在⽹站的前端。
We have found the biggest reason why a lot of beginners use the Insert Headers and Footers plugin is to add Google Analytics to their website. For that, we actually recommend using the . It’s the best Google analytics plugin for WordPress which helps you properly setup Google analytics tracking with just a few clicks, and it shows you helpful stats right inside your WordPress dashboard.
我们发现许多初学者使⽤“插⼊页眉和页脚”插件的最⼤原因是将Google Analytics(分析)添加到他们的⽹站。 为此,我们实际上建议使⽤ 。 这是适⽤于WordPress的最佳Google Analytics(分析)插件,只需单击⼏下,即可帮助您正确设置Google Analytics(分析)跟踪,并在WordPress仪表板内向您显⽰有⽤的统计信息。
We hope this article helped you to learn how to add header and footer code in WordPress easily. You may also want to see our comparison of the and the .
我们希望本⽂能帮助您学习如何在WordPress中轻松添加页眉和页脚代码。 您可能还希望查看我们对和 。
If you liked this article, then please subscribe to our for WordPress video tutorials. You can also find us on and .
如果您喜欢这篇⽂章,请订阅我们的 WordPress视频教程。 您也可以在和上到我们。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。