You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何自定义WordPress的the_archive_title()函数输出内容?

Fixing the Archive Title in Your WordPress Theme

Got it, let's get that archive title updated exactly how you want it! You've got two solid options here—one that's theme-update-safe, and another that's quick and direct.

This method lets you override the title without editing your archive.php directly, so your changes won't get wiped if you update your theme. Just add this code to your theme's functions.php file:

add_filter( 'get_the_archive_title', 'custom_projects_archive_title' );
function custom_projects_archive_title( $title ) {
    // Make sure this targets your specific Projects archive
    if ( is_post_type_archive( 'projects' ) ) {
        $title = 'Viewing All Offices I\'ve lit...';
    }
    return $title;
}

Note: If your custom post type slug isn't projects, replace that with the correct slug for your archive.

Option 2: Directly Edit archive.php

If you prefer a more straightforward approach (and don't mind re-applying changes if you update your theme), find the line in archive.php where the_archive_title() is used. It probably looks something like this:

<h1 class="archive-title"><?php the_archive_title(); ?></h1>

Replace it with your custom text, keeping the existing class to retain that big, bold styling you mentioned:

<h1 class="archive-title">Viewing All Offices I've lit...</h1>

Either way, your archive page will now show the exact title you want. If you ever need to tweak the styling later, just target the archive-title class in your theme's CSS!

内容的提问来源于stack exchange,提问作者ihoaxed

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 09:33:42