[Resolved] filters to rename title and subtitle of subpages

Home Forums Support filters to rename title and subtitle of subpages

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1361017
    Hans-Hermann Loewer

    Hi Tom and crew,
    some time ago Tom gave me the code for a filter to change the tile and subtitle on a special subpage of a site. It worked great. Now I tried to add that filter a second time, to change title and subtitle for two special subpages, but I got an error hint by adding the code in the same way a second time.

    Here is what I tried:

    add_action( 'option_blogname', 'tu_adjust_blogname' );
    function tu_adjust_blogname( $name ) {
        if ( is_page( '<strong>page name 1</strong>' ) ) {
            return '<strong>new text for the title of the page 1</strong>';
        }
        return $name;
    }
    
    add_action( 'option_blogdescription', 'tu_adjust_blogdescription' );
    function tu_adjust_blogdescription( $name ) {
        if ( is_page( '<strong>page name 1</strong>' ) ) {
            return '<strong>new subtitle for page name 1</strong>';
        }
        return $name;
    }
    
    add_action( 'option_blogname', 'tu_adjust_blogname' );
    function tu_adjust_blogname( $name ) {
        if ( is_page( '<strong>page name 2</strong>' ) ) {
            return '<strong>new text for the title of the page 2</strong>';
        }
        return $name;
    }
    
    add_action( 'option_blogdescription', 'tu_adjust_blogdescription' );
    function tu_adjust_blogdescription( $name ) {
        if ( is_page( '<strong>page name 2</strong>' ) ) {
            return '<strong>new subtitle for page name 2</strong>';
        }
        return $name;
    }

    1.) How to solve my mistake?
    2.) How can I reduce the size of the title and subtitle of each page WITHIN THAT filtercode, so that it need not be changed via the customizer for all pages in the same way … or perhaps how is that possible with Custom CSS?

    Thanks in advance!
    Hermann

    #1361287
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    You can’t re-define function names once they’ve been used.

    You can do this instead:

    add_action( 'option_blogname', 'tu_adjust_blogname' );
    function tu_adjust_blogname( $name ) {
        if ( is_page( 'page name 1' ) ) {
            return '<strong>new text for the title of the page 1</strong>';
        }
    
        if ( is_page( 'page name 2' ) ) {
            return '<strong>new text for the title of the page 2</strong>';
        }
        return $name;
    }
    
    add_action( 'option_blogdescription', 'tu_adjust_blogdescription' );
    function tu_adjust_blogdescription( $name ) {
        if ( is_page( '<strong>page name 1</strong>' ) ) {
            return '<strong>new subtitle for page name 1</strong>';
        }
    
        if ( is_page( 'page name 2' ) ) {
            return '<strong>new subtitle for page name 2</strong>';
        }
    
        return $name;
    }

    To change the size, you’d need to use CSS.

    Each page has a body class with the page ID like this:

    .page-id-123

    So you can do this on a page with the ID 123:

    .page-id-123 .main-title {
        font-size: 20px;
    }

    Hope this helps!

    #1362329
    Hans-Hermann Loewer

    That was the right solution! Thanks, Tom!

    Hermann

    #1362447
    Tom
    Lead Developer
    Lead Developer
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.