From AD INSERTER to WPCode: CTA configuration migration and priority implementation

再次无效后,我决定使用Auto Insert,Location选择"Frontend Only",并在代码中确定插入位置(图5)。

Preface

During the website maintenance process, I faced an important challenge: migrating the CTA (action call) configuration from Ad INSERTER to WPCode, and implementing more flexible priority judgments. This article will introduce this migration process and implementation method in detail.

Problem found

After migrating the website from Hueman theme to WordPress 2025 theme, I found that the articles under some series no longer show the corresponding CTA description (Figure 1). This made me realize that the CTA display mechanism needs to be reconfigured.

After migrating the website from Hueman theme to WordPress 2025 theme, I found that the articles under some series no longer show the corresponding CTA description (Figure 1)


problem analysis

After analysis, I found that AD INSERTER has a compatibility problem in the new topic. So I decided to migrate the CTA configuration to WPCode, and can achieve a more flexible priority judgment (Figure 2).

After analysis, I found that AD INSERTER has a compatibility problem in the new topic. So I decided to migrate the CTA configuration to WPCode, and can achieve a more flexible priority judgment (Figure 2).

Solution Exploration: Series Category Solutions

Initially, I thought about implementing CTA configuration based on series categories. The advantages of this scheme are:

  1. Clear hierarchy: Series categories can better organize and manage multiple series
  2. strong extensibility: New series can be easily added to existing categories
  3. Logic and intuitive: The relationship between the series can be better understood through the parent relationship
    However, during the implementation, I found some challenges with this scheme:
  • Series Categories are complex: Need to make sure that each series is properly assigned to the corresponding category
  • Difficult to debug: In WordPress, the hierarchy relationship of series categories is sometimes not intuitive enough
  • Time limit: Due to the tight project time, this scheme cannot be fully realized and tested
    Ultimately, due to time constraints, I decided to temporarily give up the series-based scheme and use the more direct-based implementation of the series-based slug.

Final Scheme: Migrate to WPCode with Priority Implementation

Step 1: Add ShortCode in the theme editor

First, I’m in the theme editor, a single article – template, add shortcode block after content block, then paste wpcode

(Figure 3).

Figure 3 In the theme editor, a single article - template, add a shortcode block after the content block, and then paste it
Figure 3 In the theme editor, a single article – template, add a shortcode block after the content block, and then paste it

Step 2: Try Auto Insert

However, this method is not valid. So, I try to use Auto Insert, the location selects ‘insert after content’ (Figure 4).

However, this method is not valid. So, I try to use Auto Insert, the location selects "insert after content" (Figure 4).

Step 3: Adjust the Auto Insert settings

After it doesn’t work again, I decided to use Auto Insert, the location selects ‘frontend only’ and determines the insertion position in the code (Figure 5).

After it doesn't work again, I decided to use Auto Insert, the location selects "frontend only" and determines the insertion position in the code (Figure 5).

Step 4: Successful Implementation

In the end, this method succeeded! The articles under a series will be displayed based on the descriptions under this series (Figure 6).

In the end, this method succeeded! The articles under a series will be displayed based on the descriptions under this series (Figure 6).

code implementation

The following is the complete code implementation, which includes the priority judgment logic:

PHP
// ==========================================
// 使用 WordPress 原生钩子,强制在内容后插入
// ==========================================
add_filter('the_content', 'custom_desc_and_ads_inserter', 20);

function custom_desc_and_ads_inserter($content) {
    // 1. 仅在单篇文章页面执行,排除后台、Feed、首页等
    if (!is_singular('post') || is_admin() || is_feed()) {
        return $content;
    }

    // 2. 安全获取文章ID
    $post_id = get_the_ID();
    if (!$post_id) {
        global $wp_query;
        if (isset($wp_query->queried_object_id)) {
            $post_id = $wp_query->queried_object_id;
        }
    }

    // 3. 初始化变量
    $current_lang = '';
    $current_series_slugs = array();

    if (class_exists('SitePress')) {
        $current_lang = apply_filters('wpml_current_language', null);
    }
    if (empty($current_lang)) {
        $current_lang = (false !== strpos($_SERVER['REQUEST_URI'], '/en/')) ? 'en' : 'zh';
    }

    if ($post_id) {
        $current_series = get_the_terms($post_id, 'series');
        if (is_array($current_series) && !is_wp_error($current_series)) {
            $current_series_slugs = wp_list_pluck($current_series, 'slug');
        }
    }

    $output_html = '';

    // ==========================================
    // 4. 优先级判断逻辑 (保持不变)
    // ==========================================
    if ($current_lang === 'zh' && in_array('self-hosted-vpn', $current_series_slugs)) {
        $output_html .= <<<HTML
<div class="custom-desc-block">
    <p><strong>拒绝折腾 | 专属 WireGuard VPN 代搭建服务</strong></p>
    <p>本频道长期实测各类网络优化方案。<strong>自用线路已连续稳定运行超过 1 个月,全程无掉线记录。</strong>如果你不想反复踩坑、折腾复杂的服务器与协议配置,欢迎联系我获取专属解决方案。</p>
    <p><strong>适合以下用户:</strong><br>
✅ ChatGPT、Claude、Gemini 等 AI 工具使用者<br>
✅ 海外远程办公用户<br>
✅ 技术学习与开发环境访问需求<br>
✅ 不想长期折腾 VPS 与代理配置的用户<br>
✅ 希望拥有专属节点而非公共机场的用户
    </p>
    <p><strong>服务内容:</strong><br>
<strong>远程代搭建</strong>:在你自己的服务器上部署专属 VPN,数据完全掌控。<br>
<strong>免费试用</strong>:可申请免费试用一个月我的自建节点。<br>
<strong>分流优化</strong>:针对 AI 工具、开发环境及日常使用进行深度优化。<br>
<strong>后续支持</strong>:部署完成后可协助排查常见问题。
    </p>
    <p>如需了解方案或申请试用,请直接联系我,并注明:<strong>VPN 咨询</strong></p>
    <p><strong>联系方式:</strong><br>
Telegram:@shuijingwan<br>
微信:13980074657<br>
邮箱:<a href="mailto:shuijingwanwq@gmail.com">shuijingwanwq@gmail.com</a></p>
</div>
HTML;
    } elseif ($current_lang === 'en' && in_array('self-hosted-vpn-en', $current_series_slugs)) {
        $output_html .= <<<HTML
<div class="custom-desc-block">
    <p><strong>Stop the Hassle | Dedicated WireGuard VPN Deployment Service</strong></p>
    <p>I continuously test and evaluate various network optimization solutions. <strong>My personal setup has been running stably for over a month with zero downtime.</strong> If you are tired of troubleshooting, experimenting with different protocols, or managing complex server configurations, feel free to contact me for a dedicated solution.</p>
    <p><strong>Ideal For:</strong><br>
✅ Users of AI tools such as ChatGPT, Claude, and Gemini<br>
✅ Remote workers who rely on stable international connectivity<br>
✅ Developers and technical learners who need access to global resources<br>
✅ Users who do not want to spend time managing VPS and proxy configurations<br>
✅ Anyone who prefers a private VPN server instead of shared public services
    </p>
    <p><strong>What I Offer:</strong><br>
<strong>Remote Deployment</strong>: Deploy a dedicated WireGuard VPN on your own server with full control over your data.<br>
<strong>Free Trial</strong>: Apply for a one-month free trial of my self-hosted VPN node before making a decision.<br>
<strong>Traffic Routing Optimization</strong>: Fine-tuned routing rules optimized for AI tools, development environments, and everyday browsing.<br>
<strong>Post-Deployment Support</strong>: Assistance with setup, client configuration, and troubleshooting after deployment.
    </p>
    <p>If you would like to learn more or apply for a free trial, please contact me directly and mention: <strong>VPN Consultation</strong>.</p>
    <p><strong>Contact Me:</strong><br>
Telegram: @shuijingwan<br>
WeChat: 13980074657<br>
Email: <a href="mailto:shuijingwanwq@gmail.com">shuijingwanwq@gmail.com</a></p>
</div>
HTML;
    } elseif ($current_lang === 'zh' && array_intersect($current_series_slugs, array('wp-perf-notes', 'wp-blog-multilingual-guide-zh', 'blog-seo-log', 'exploring-blog-business-models', 'ad-inserter-usage-notes', 'from-classical-to-block-theme-migration'))) {
        $output_html .= <<<HTML
<div class="custom-desc-block">
    <p><strong>技术博客运营与商业化咨询服务</strong></p>
    <p>本站已持续运营超过 10 年,累计发布 1000+ 篇原创技术文章,长期实践 WordPress 网站建设、性能优化、多语言运营、Google SEO 以及广告变现等方向。<strong>所有经验均来自真实网站运营过程中的持续实践与验证。</strong>如果你正在运营个人博客、技术网站或独立开发者项目,希望获得更多自然流量并探索网站商业化路径,欢迎联系我交流。</p>
    <p><strong>适合以下用户:</strong><br>
✅ 技术博客运营者<br>
✅ 独立开发者与个人站长<br>
✅ SaaS 产品官网运营团队<br>
✅ 希望拓展海外流量的网站运营者<br>
✅ 希望通过网站获得收入的内容创作者
    </p>
    <p><strong>服务内容:</strong><br>
<strong>WordPress 性能优化</strong><br>
<strong>SEO 优化咨询</strong><br>
<strong>多语言网站建设</strong><br>
<strong>广告收益优化</strong><br>
<strong>博客运营与商业化咨询</strong>
    </p>
    <p>如需了解方案或交流相关问题,请直接联系我,并注明:<strong>博客运营咨询</strong></p>
    <p><strong>联系方式:</strong><br>
Telegram:@shuijingwan<br>
微信:13980074657<br>
邮箱:<a href="mailto:shuijingwanwq@gmail.com">shuijingwanwq@gmail.com</a></p>
</div>
HTML;
    } elseif ($current_lang === 'en' && array_intersect($current_series_slugs, array('wp-perf-notes-en', 'wp-blog-multilingual-guide', 'blog-seo-log-en', 'exploring-blog-business-models-en', 'ad-inserter-usage-notes-en', 'from-classical-to-block-theme-migration-en'))) {
        $output_html .= <<<HTML
<div class="custom-desc-block">
    <p><strong>Technical Blog Growth & Monetization Consulting</strong></p>
    <p>I have been running my personal technology blog for more than 10 years and have published over 1,000 original articles covering WordPress optimization, multilingual websites, Google SEO, content strategy, and website monetization. <strong>All insights shared on this site come from real-world operation and long-term experimentation.</strong> If you are building a blog, developer website, SaaS project, or content-driven platform, I would be happy to share practical experience and optimization suggestions.</p>
    <p><strong>Ideal For:</strong><br>
✅ Technical bloggers<br>
✅ Independent developers<br>
✅ SaaS website owners<br>
✅ Content creators seeking organic traffic growth<br>
✅ Website owners interested in monetization opportunities
    </p>
    <p><strong>What I Offer:</strong><br>
✅ WordPress Performance Optimization<br>
✅ SEO Consulting<br>
✅ Multilingual Website Setup<br>
✅ Ad Revenue Optimization<br>
✅ Blog Growth & Monetization Consulting
    </p>
    <p>If you would like to discuss your website, traffic growth strategy, or monetization opportunities, please contact me and mention: <strong>Blog Growth Consultation</strong>.</p>
    <p><strong>Contact Me:</strong><br>
Telegram: @shuijingwan<br>
WeChat: 13980074657<br>
Email: <a href="mailto:shuijingwanwq@gmail.com">shuijingwanwq@gmail.com</a></p>
</div>
HTML;
    } elseif ($current_lang === 'zh' && in_array('yii2-advanced-api-rpc-i18n-logging', $current_series_slugs)) {
        $output_html .= <<<HTML
<div class="custom-desc-block">
    <p><strong>PHP / Yii2 企业系统开发与架构咨询服务</strong></p>
    <p>拥有 15 年以上 Web 开发经验,长期从事企业管理系统、数据平台、API 服务及高并发业务系统开发。曾主导多个大型项目的架构设计与核心模块研发,具备丰富的 Yii2 企业级项目实战经验。</p>
    <p><strong>适合以下项目:</strong><br>
✅ 企业管理系统<br>
✅ ERP / CRM 系统<br>
✅ RESTful API 平台<br>
✅ 多租户 SaaS 系统<br>
✅ 老旧 PHP 系统升级改造
    </p>
    <p><strong>服务内容:</strong><br>
✅ Yii2 企业项目开发<br>
✅ RESTful API 设计与开发<br>
✅ 系统架构设计<br>
✅ 性能优化与故障排查<br>
✅ 长期技术支持与维护
    </p>
    <p>如需咨询,请联系我,并注明:<strong>Yii2 项目咨询</strong></p>
    <p><strong>联系方式:</strong><br>
Telegram:@shuijingwan<br>
微信:13980074657<br>
邮箱:<a href="mailto:shuijingwanwq@gmail.com">shuijingwanwq@gmail.com</a></p>
</div>
HTML;
    } elseif ($current_lang === 'en' && in_array('yii2-advanced-api-rpc-i18n-logging-en', $current_series_slugs)) {
        $output_html .= <<<HTML
<div class="custom-desc-block">
    <p><strong>PHP / Yii2 Enterprise Development & Architecture Consulting</strong></p>
    <p>With more than 15 years of web development experience, I have worked extensively on enterprise platforms, business management systems, API services, and large-scale web applications. I have led architecture design and core system development for multiple production projects using Yii2.</p>
    <p><strong>Ideal For:</strong><br>
✅ Enterprise applications<br>
✅ ERP / CRM systems<br>
✅ RESTful API platforms<br>
✅ Multi-tenant SaaS projects<br>
✅ Legacy PHP modernization
    </p>
    <p><strong>What I Offer:</strong><br>
✅ Yii2 Enterprise Development<br>
✅ API Architecture Design<br>
✅ System Architecture Consulting<br>
✅ Performance Optimization<br>
✅ Long-Term Technical Support
    </p>
    <p>Please contact me and mention: <strong>Yii2 Project Consultation</strong>.</p>
    <p><strong>Contact Me:</strong><br>
Telegram: @shuijingwan<br>
WeChat: 13980074657<br>
Email: <a href="mailto:shuijingwanwq@gmail.com">shuijingwanwq@gmail.com</a></p>
</div>
HTML;
    } elseif ($current_lang === 'zh' && in_array('practical-go-concurrency-step-by-step', $current_series_slugs)) {
        $output_html .= <<<HTML
<div class="custom-desc-block">
    <p><strong>Go 后端开发与架构咨询服务</strong></p>
    <p>长期从事 Go 语言后端开发与高并发系统建设,具备 API 服务、实时通信、任务调度、微服务架构及系统优化经验。相关实践内容均来自真实生产环境项目。</p>
    <p><strong>适合以下项目:</strong><br>
✅ 高并发业务系统<br>
✅ API 服务平台<br>
✅ WebSocket 实时通信<br>
✅ 微服务架构建设<br>
✅ 性能优化与系统重构
    </p>
    <p><strong>服务内容:</strong><br>
✅ Go 后端开发<br>
✅ API 服务开发<br>
✅ 微服务架构设计<br>
✅ 系统性能优化<br>
✅ 技术咨询与长期支持
    </p>
    <p>如需咨询,请联系我,并注明:<strong>Go 项目咨询</strong></p>
    <p><strong>联系方式:</strong><br>
Telegram:@shuijingwan<br>
微信:13980074657<br>
邮箱:<a href="mailto:shuijingwanwq@gmail.com">shuijingwanwq@gmail.com</a></p>
</div>
HTML;
    } elseif ($current_lang === 'en' && in_array('practical-go-concurrency-step-by-step-en', $current_series_slugs)) {
        $output_html .= <<<HTML
<div class="custom-desc-block">
    <p><strong>Go Backend Development & Architecture Consulting</strong></p>
    <p>I specialize in Go backend development, high-concurrency systems, API platforms, real-time communication services, and scalable backend architectures. All content shared in this series is based on real-world production experience.</p>
    <p><strong>Ideal For:</strong><br>
✅ High-concurrency applications<br>
✅ API service platforms<br>
✅ Real-time communication systems<br>
✅ Microservices architecture<br>
✅ Backend modernization projects
    </p>
    <p><strong>What I Offer:</strong><br>
✅ Go Backend Development<br>
✅ API Platform Development<br>
✅ Microservices Architecture Design<br>
✅ Performance Optimization<br>
✅ Long-Term Technical Support
    </p>
    <p>Please contact me and mention: <strong>Go Project Consultation</strong>.</p>
    <p><strong>Contact Me:</strong><br>
Telegram: @shuijingwan<br>
WeChat: 13980074657<br>
Email: <a href="mailto:shuijingwanwq@gmail.com">shuijingwanwq@gmail.com</a></p>
</div>
HTML;
    } elseif ($current_lang === 'zh' && in_array('windows-to-ubuntu', $current_series_slugs)) {
        $output_html .= <<<HTML
<div class="custom-desc-block">
    <p><strong>Linux 服务器部署与运维咨询服务</strong></p>
    <p>长期使用 Ubuntu、Debian 等 Linux 系统进行开发与运维工作,积累了服务器部署、Docker 容器化、Nginx 配置、网站迁移及性能优化等实践经验。</p>
    <p><strong>适合以下场景:</strong><br>
✅ Linux 环境迁移<br>
✅ 网站部署上线<br>
✅ Docker 容器化部署<br>
✅ Nginx 配置优化<br>
✅ 服务器性能调优
    </p>
    <p><strong>服务内容:</strong><br>
✅ Linux 环境搭建<br>
✅ 网站部署与迁移<br>
✅ Docker 配置与维护<br>
✅ Nginx 优化<br>
✅ 长期运维支持
    </p>
    <p>如需咨询,请联系我,并注明:<strong>Linux 运维咨询</strong></p>
    <p><strong>联系方式:</strong><br>
Telegram:@shuijingwan<br>
微信:13980074657<br>
邮箱:<a href="mailto:shuijingwanwq@gmail.com">shuijingwanwq@gmail.com</a></p>
</div>
HTML;
    } elseif ($current_lang === 'en' && in_array('windows-to-ubuntu-migration-configuration-guide', $current_series_slugs)) {
        $output_html .= <<<HTML
<div class="custom-desc-block">
    <p><strong>Linux Server Deployment & Operations Consulting</strong></p>
    <p>I have extensive experience working with Ubuntu, Debian, Docker, Nginx, and cloud servers in production environments. This includes server deployment, website migration, performance tuning, and long-term maintenance.</p>
    <p><strong>Ideal For:</strong><br>
✅ Linux migration projects<br>
✅ Website deployment<br>
✅ Docker-based environments<br>
✅ Nginx optimization<br>
✅ Server performance tuning
    </p>
    <p><strong>What I Offer:</strong><br>
✅ Linux Environment Setup<br>
✅ Website Migration & Deployment<br>
✅ Docker Configuration & Maintenance<br>
✅ Nginx Optimization<br>
✅ Long-Term Technical Support
    </p>
    <p>Please contact me and mention: <strong>Linux Operations Consultation</strong>.</p>
    <p><strong>Contact Me:</strong><br>
Telegram: @shuijingwan<br>
WeChat: 13980074657<br>
Email: <a href="mailto:shuijingwanwq@gmail.com">shuijingwanwq@gmail.com</a></p>
</div>
HTML;
    } elseif ($current_lang === 'zh' && (custom_in_category_tree('laravel') || custom_in_category_tree('yii-2'))) {
        $output_html .= <<<HTML
<div class="custom-desc-block">
    <p><strong>PHP / Yii2 / Laravel 企业系统开发与架构咨询服务</strong></p>
    <p>拥有 15 年以上 Web 开发经验,长期从事企业管理系统、数据平台、API 服务及高并发业务系统开发。熟悉 PHP、Yii2、Laravel、MySQL、Redis 等技术栈,曾主导多个大型项目的架构设计与核心模块研发,具备丰富的企业级项目实战经验。</p>
    <p><strong>适合以下项目:</strong><br>
✅ 企业管理系统<br>
✅ ERP / CRM 系统<br>
✅ RESTful API 平台<br>
✅ 多租户 SaaS 系统<br>
✅ 老旧 PHP 系统升级改造
    </p>
    <p><strong>服务内容:</strong><br>
✅ PHP / Yii2 / Laravel 项目开发<br>
✅ RESTful API 设计与开发<br>
✅ 系统架构设计<br>
✅ 性能优化与故障排查<br>
✅ 长期技术支持与维护
    </p>
    <p>如需咨询,请联系我,并注明:<strong>PHP 项目咨询</strong></p>
    <p><strong>联系方式:</strong><br>
Telegram:@shuijingwan<br>
微信:13980074657<br>
邮箱:<a href="mailto:shuijingwanwq@gmail.com">shuijingwanwq@gmail.com</a></p>
</div>
HTML;
    } elseif ($current_lang === 'en' && (custom_in_category_tree('laravel-en') || custom_in_category_tree('yii-2-en'))) {
        $output_html .= <<<HTML
<div class="custom-desc-block">
    <p><strong>PHP / Yii2 / Laravel Enterprise Development & Architecture Consulting</strong></p>
    <p>With more than 15 years of web development experience, I have worked extensively on enterprise platforms, business management systems, API services, and large-scale web applications. My expertise covers PHP, Yii2, Laravel, MySQL, Redis, RESTful APIs, and scalable backend architectures. I have led architecture design and core system development for multiple production projects and long-term enterprise systems.</p>
    <p><strong>Ideal For:</strong><br>
✅ Enterprise applications<br>
✅ ERP / CRM systems<br>
✅ RESTful API platforms<br>
✅ Multi-tenant SaaS projects<br>
✅ Legacy PHP system modernization
    </p>
    <p><strong>What I Offer:</strong><br>
✅ PHP / Yii2 / Laravel Development<br>
✅ RESTful API Design & Development<br>
✅ System Architecture Consulting<br>
✅ Performance Optimization & Troubleshooting<br>
✅ Long-Term Technical Support & Maintenance
    </p>
    <p>If you would like to discuss your project, please contact me and mention: <strong>PHP Project Consultation</strong>.</p>
    <p><strong>Contact Me:</strong><br>
Telegram: @shuijingwan<br>
WeChat: 13980074657<br>
Email: <a href="mailto:shuijingwanwq@gmail.com">shuijingwanwq@gmail.com</a></p>
</div>
HTML;
    } elseif ($current_lang === 'zh' && (custom_in_category_tree('linux') || custom_in_category_tree('cloud-vendor'))) {
        $output_html .= <<<HTML
<div class="custom-desc-block">
    <p><strong>Linux 服务器部署与运维咨询服务</strong></p>
    <p>长期使用 Ubuntu、Debian 等 Linux 系统进行开发与运维工作,积累了服务器部署、Docker 容器化、Nginx 配置、网站迁移及性能优化等实践经验。</p>
    <p><strong>适合以下场景:</strong><br>
✅ Linux 环境迁移<br>
✅ 网站部署上线<br>
✅ Docker 容器化部署<br>
✅ Nginx 配置优化<br>
✅ 服务器性能调优
    </p>
    <p><strong>服务内容:</strong><br>
✅ Linux 环境搭建<br>
✅ 网站部署与迁移<br>
✅ Docker 配置与维护<br>
✅ Nginx 优化<br>
✅ 长期运维支持
    </p>
    <p>如需咨询,请联系我,并注明:<strong>Linux 运维咨询</strong></p>
    <p><strong>联系方式:</strong><br>
Telegram:@shuijingwan<br>
微信:13980074657<br>
邮箱:<a href="mailto:shuijingwanwq@gmail.com">shuijingwanwq@gmail.com</a></p>
</div>
HTML;
    } elseif ($current_lang === 'en' && (custom_in_category_tree('linux-en') || custom_in_category_tree('cloud-vendor-en'))) {
        $output_html .= <<<HTML
<div class="custom-desc-block">
    <p><strong>Linux Server Deployment & Operations Consulting</strong></p>
    <p>I have extensive experience working with Ubuntu, Debian, Docker, Nginx, and cloud servers in production environments. This includes server deployment, website migration, performance tuning, and long-term maintenance.</p>
    <p><strong>Ideal For:</strong><br>
✅ Linux migration projects<br>
✅ Website deployment<br>
✅ Docker-based environments<br>
✅ Nginx optimization<br>
✅ Server performance tuning
    </p>
    <p><strong>What I Offer:</strong><br>
✅ Linux Environment Setup<br>
✅ Website Migration & Deployment<br>
✅ Docker Configuration & Maintenance<br>
✅ Nginx Optimization<br>
✅ Long-Term Technical Support
    </p>
    <p>Please contact me and mention: <strong>Linux Operations Consultation</strong>.</p>
    <p><strong>Contact Me:</strong><br>
Telegram: @shuijingwan<br>
WeChat: 13980074657<br>
Email: <a href="mailto:shuijingwanwq@gmail.com">shuijingwanwq@gmail.com</a></p>
</div>
HTML;
    } else {
        if ($current_lang === 'zh') {
            $output_html .= <<<HTML
<div class="custom-desc-block">
    <p>我是拥有 15+ 年经验的 PHP / Go 后端工程师。如需以下服务,欢迎联系我(更多介绍请查看 <a href="https://www.shuijingwanwq.com/en/about-me-contact-2/" target="_blank" rel="noopener noreferrer">关于我 & 合作</a>):</p>
    <ul>
        <li>✅ PHP / Go 项目开发与维护</li>
        <li>✅ 系统架构设计与技术咨询</li>
        <li>✅ 网站性能优化与故障排查</li>
        <li>✅ Linux 服务器部署与运维</li>
        <li>✅ 网络环境优化与远程支持</li>
        <li>✅ 长期技术顾问合作</li>
    </ul>
    <p>
        微信:13980074657<br>
        邮箱:shuijingwanwq@gmail.com<br>
        Telegram:@shuijingwan<br>
        GitHub:https://github.com/shuijingwan
    </p>
</div>
HTML;
        } else {
            $output_html .= <<<HTML
<div class="custom-desc-block">
    <p>I am a PHP / Go backend engineer with 15+ years of experience. If you need any of the following services, feel free to contact me (more details: <a href="https://www.shuijingwanwq.com/en/about-me-contact-2/" target="_blank" rel="noopener noreferrer">About Me & Collaboration</a>):</p>
    <ul>
        <li>✅ PHP / Go project development and maintenance</li>
        <li>✅ System architecture design and technical consulting</li>
        <li>✅ Performance optimization and troubleshooting</li>
        <li>✅ Linux server deployment and operations</li>
        <li>✅ Network environment optimization and remote support</li>
        <li>✅ Long-term technical consulting</li>
    </ul>
    <p>
        WeChat: 13980074657<br>
        Email: shuijingwanwq@gmail.com<br>
        Telegram: @shuijingwan<br>
        GitHub: https://github.com/shuijingwan
    </p>
</div>
HTML;
        }
    }

    // 5. 将描述追加到文章内容末尾
    return $content . $output_html;
}

// ==========================================
// 辅助函数:检查分类树
// ==========================================
function custom_in_category_tree($cat_slug) {
    global $post;
    if (!is_object($post) || !isset($post->ID)) return false;
    
    $cat = get_category_by_slug($cat_slug);
    if (!$cat) return false;
    $term_ids = get_term_children($cat->term_id, 'category');
    $term_ids[] = $cat->term_id;
    return in_category($term_ids, $post->ID);
}

Priority Implementation: Classification Tree Functional Testing

I also tested demo1_custom_in_category_tree(linux) function. It is found that a certain article does not belong to the classification Linux, but only belongs to the Sun classification Ubuntu 26.04 (Figure 7).

I also tested CUSTOM_IN_CATEGORY_TREE(linux) function. It is found that a certain article does not belong to the classification Linux, but only belongs to the Sun classification Ubuntu 26.04 (Figure 7).

Priority Validation: Expected Results

Even if the article belongs only to the Sun classification, it will still display CUSTOM_IN_CATEGORY_TREE(linux) The description, which is in line with our priorities expectation (Figure 8).

Surprisingly, even if the article belongs only to the Sun category, CUSTOM_IN_CATEGORY_TREE(linux) in the description, which is in line with our priorities expectation (Figure 8).

Conclusion

With this migration, I successfully migrated the CTA configuration from the AD INSERTER to WPCode and implemented a more flexible priority judgment. Although initially considered a series-based scheme, due to time constraints, the priority implementation based on the series Slug was finally selected. The new solution not only solves the problem of the series description display after the theme switching, but also provides a more powerful classification tree function.
Hope this article is helpful for developers who are considering similar migrations!

评论

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.