如何自定义WordPress的the_archive_title()函数输出内容?
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.
Option 1: Use a WordPress Filter (Recommended)
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

