> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://helpdesk.ezmob.com/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# 如何在 WordPress 的 <head> 中添加广告代码

使用插件、子主题或 `wp_head` 钩子，将 EZmob 代码粘贴到 WordPress 网站的 `<head>` 部分。注意：wordpress.com 地址无法通过验证。只有使用自有域名的网站才能通过验证并获得优质广告需求。

## 复制广告代码

1. 在 EZmob 控制面板中，打开 **网站与投放** → **您的投放**。
2. 点击该广告位上的代码图标（**查看脚本**）。
3. 点击 **复制脚本**。

## 方法 1：使用插件（最简单）

1. 安装任意一款可在网站头部插入代码的插件。
2. 将代码粘贴到插件中适用于所有页面的头部（`<head>`）字段。
3. 保存。

## 方法 2：编辑子主题

1. 打开子主题的 `header.php`。请勿编辑父主题，否则主题更新会覆盖您的修改。
2. 将代码粘贴到 `</head>` 的正上方。
3. 保存文件。

## 方法 3：使用 wp_head 钩子

将以下代码添加到主题 `functions.php` 的末尾，并将注释替换为您的代码：

```php
function ezmob_insert_header() {
    ?>
    <!-- Paste your EZmob code here -->
    <?php
}
add_action( 'wp_head', 'ezmob_insert_header' );
```

您也可以用上述任一方法添加网站的 **验证代码**，然后在 EZmob 中点击 **验证**。

## Header Bidding 横幅

Header Bidding 代码以 `<div id="container1"></div>` 结尾，用于标记横幅的显示位置。

1. 按上述方法，将不含该 `<div>` 的代码添加到 `<head>`。
2. 在 WordPress 中，前往 **外观**（Appearance）→ **小工具**（Widgets）。
3. 在侧边栏中添加一个 **自定义 HTML**（Custom HTML）小工具，粘贴 `<div id="container1"></div>` 并保存。

## 截图

![网站与投放 → 您的投放，横幅脚本视图，突出显示“复制脚本”](https://zjcgneywpnkgamzggapu.supabase.co/storage/v1/object/public/helpdesk-media/pub/05812667-1.png)

*截图为英文界面。您可以将控制面板语言切换为中文。*

- *截图：WordPress“外观”→“小工具”，包含容器 div 的“自定义 HTML”小工具*

## 相关文章

- [如何创建广告位并获取广告标签](https://helpdesk.ezmob.com/zh/article/how-to-create-a-placement-and-obtain-your-ad-tag-1jjrdjs/)
- [如何将网站添加到 EZmob 进行变现](https://helpdesk.ezmob.com/zh/article/how-to-add-your-site-to-ezmob-for-monetization-10hgtet/)
- [通过 EZmob 头部竞价（Header Bidding）实现变现](https://helpdesk.ezmob.com/zh/article/header-bidding-monetization-with-ezmob-17ooltx/)
- [站长 ads.txt 设置指南](https://helpdesk.ezmob.com/zh/article/adstxt-for-publishers-1vs9532/)
- [如何在 Blogger 的 <head> 部分添加广告代码](https://helpdesk.ezmob.com/zh/article/how-to-add-an-ad-tag-to-head-section-in-blogger-platform-1qjgse5/)