- This topic has 3 replies, 2 voices, and was last updated 3 years, 9 months ago by Tom.
-
AuthorPosts
-
July 12, 2020 at 8:38 am #1361017Hans-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!
HermannJuly 12, 2020 at 2:29 pm #1361287TomLead DeveloperLead DeveloperHi 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!
July 13, 2020 at 11:18 am #1362329Hans-Hermann LoewerThat was the right solution! Thanks, Tom!
Hermann
July 13, 2020 at 2:07 pm #1362447TomLead DeveloperLead DeveloperNo problem 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.