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

如何在WordPress中添加副标题并在浏览循环仅显示标题?

Hey there! Let's tackle your two WordPress issues step by step—fixing the subtitle display format and hiding post content on archive/category loops.

1. Customize the Secondary Title Display Format

The default "Main Title: Secondary Title" format from the Secondary Title plugin can be easily adjusted using a PHP filter (no need to edit plugin core files, which would get overwritten on updates).

  • Open your theme's functions.php file (or use a code snippet plugin like Code Snippets for safer edits) and add this code:
add_filter('secondary_title_the_title', 'custom_secondary_title_layout', 10, 3);
function custom_secondary_title_layout($combined_title, $main_title, $secondary_title) {
    // Customize the HTML structure here—this example puts the subtitle on a new line with a custom class
    return $main_title . '<br><span class="secondary-title">' . $secondary_title . '</span>';
}

You can tweak the HTML to fit your design: wrap titles in divs, add spacing, or use different text styles. The secondary-title class lets you add custom CSS later (e.g., make it smaller or grayed out).

2. Hide Post Content on Archive/Category Loops

To make loop pages (categories, archives, tags) only show titles + subtitles (no content/excerpt), you have two straightforward options:

Option 1: Use Code Snippets (No Template Edits)

Add this code to functions.php or your code snippet plugin to suppress content on loop pages:

add_filter('the_content', 'remove_content_from_archives');
function remove_content_from_archives($content) {
    // Check if we're on an archive, category, or tag page
    if (is_archive() || is_category() || is_tag()) {
        return ''; // Return empty to hide content
    }
    return $content; // Keep content visible on single post pages
}

If your theme uses the_excerpt() instead of the_content() on loops, swap the filter to target excerpts:

add_filter('the_excerpt', 'remove_excerpt_from_archives');
function remove_excerpt_from_archives($excerpt) {
    if (is_archive() || is_category() || is_tag()) {
        return '';
    }
    return $excerpt;
}

Option 2: Edit Theme Template Files (More Direct)

Locate your theme's loop template files (usually category.php, archive.php, or index.php if it uses a universal template). Find the section that displays post content/excerpt—it’ll look something like this:

<div class="entry-content">
    <?php the_content(); ?>
</div>

Delete or comment out the the_content() (or the_excerpt()) line. Only keep the title output (the_title()) to show just the main and secondary titles.

Pro tip: Always use a child theme when editing template files—this prevents your changes from being lost when the parent theme updates.

After making these changes, refresh your category/archive pages: you’ll see only the formatted main + secondary titles, with no post content. Single post pages will still display full content as expected.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 06:18:01