Viewing 10 replies - 1 through 10 (of 10 total)
  • Since you’re using the Twenty Twenty-One theme, you can adjust the CSS for this via the Customizer. Go to Appearance > Customize in your WordPress admin. Once on the next screen, open the “Additional CSS” panel and add the following code to the text box:

    
    .singular .entry-title {
        font-size: 6rem;
    }
    

    6rem is what your theme currently uses for single page titles. You can lower that to a number of your choosing.

    Once you’ve found the size that you prefer, click the publish button at the top of the customizer panel.

    Thread Starter kufloyd

    (@kufloyd)

    Thanks for the quick reply. It works for pages, but I have a couple of category-based blog pages, like https://kunalmehra.com/category/writing/, where it still shows the larger font. Any idea how to change those?

    Thanks.

    Sure. It looks like the theme uses .page-title for category pages, so you can combine the above code with it. You can replace the above code with this new code:

    
    .singular .entry-title,
    .page-title {
    	font-size: 6rem;
    }
    

    Of course, change the 6rem to your preferred size.

    Thread Starter kufloyd

    (@kufloyd)

    Thanks again…that works. If I may, one other question: Right now https://kunalmehra.com/category/films/ displays “category: Films” as the title. Is there a way for it to just say “Films” and not prefix the word ‘category’?

    Awesome! I glad we got the font size adjusted.

    I’m 100% certain there is a way to filter the title to remove the prefix. However, I’m hopping offline for the day. If no one else jumps in to answer, I’ll be back on to help with that tomorrow.

    Sorry for the wait on this, but I was just looping back around. If you want to go the DIY route, you can drop one of the following code snippets into your theme’s functions.php (preferably a child theme if you have one active).

    If you only want to remove the prefix for categories, use this code:

    
    add_filter( 'get_the_archive_title_prefix', function( $prefix ) {
    	return is_category() ? '' : $prefix;
    } );
    

    If you want to do it for categories, tags, authors, and all other archive-type pages with a prefix, use this code:

    
    add_filter( 'get_the_archive_title_prefix', '__return_empty_string' );
    

    As an alternative, I know of at least one plugin that has an option for this. It’s called Twentig. It actually has a lot of neat add-ons for Twenty Twenty-One, but it might be overkill for what you need.

    Thread Starter kufloyd

    (@kufloyd)

    Thanks…I tried this code:
    add_filter(‘get_the_archive_title_prefix’, function( $prefix ) {
    return is_category() ? ” : $prefix;
    });

    but it still displays ‘category’ as a prefix: https://kunalmehra.com/category/films/

    Not a big deal to have the category prefix, but just thought I’d check if it’s possible to do it w/o too much effort. Like you said, the Twentig plugin might not be worth the effort.

    I went back and re-tested the code with Twenty Twenty-One. It’s definitely working for me. My best guess is that, maybe, you might have pasted it in the wrong place.

    Just to verify, did you put it into your active theme’s functions.php file?

    Here’s what the top of my wp-content/themes/twentytwentyone/functions.php file looks like with the working code:

    
    <?php
    /**
     * Functions and definitions
     *
     * @link https://developer.wordpress.org/themes/basics/theme-functions/
     *
     * @package WordPress
     * @subpackage Twenty_Twenty_One
     * @since Twenty Twenty-One 1.0
     */
     
    add_filter( 'get_the_archive_title_prefix', function( $prefix ) {
    	return is_category() ? '' : $prefix;
    } );
    

    If you have that and it’s still not working, my second best guess would be that a plugin is altering it (sometimes SEO-related plugins do their own thing with category titles).

    Thread Starter kufloyd

    (@kufloyd)

    I was doing it in the wrong place (in additional CSS). Now, doing it in functions.php works.

    Thanks.

    Awesome! Glad you got it working.

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Change page title font size’ is closed to new replies.