[Resolved] Add a css class to site-title

Home Forums Support [Resolved] Add a css class to site-title

Home Forums Support Add a css class to site-title

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2029882
    Adnan

    How can I add the “notranslate” class only to the site-title in the header?

    #2029971
    Ying
    Staff
    Customer Support

    Hi Adnan,

    Try this PHP snippet:

    add_filter( 'generate_site_title_output', function( $output ) {
    	return sprintf(
    		'<%1$s class="main-title notranslate" itemprop="headline">
    		    %3$s
    		</%1$s>',
    		( is_front_page() && is_home() ) ? 'h1' : 'p',
    		esc_url( apply_filters( 'generate_site_title_href', home_url( '/' ) ) ),
    		get_bloginfo( 'name' )
    	);
    });

    Adding PHP: https://docs.generatepress.com/article/adding-php/

    Let me know if you need further assistance ๐Ÿ™‚

    #2030218
    Adnan

    Hi Ying,
    thank you. Works perfect. I have added the Link too (code below). Thank you and kind regards. Adnan

    add_filter( 'generate_site_title_output', function( $output ) {
    	return sprintf(
    		'<%1$s class="main-title notranslate" itemprop="headline">
    		    <a href="%2$s">%3$s</a>
    		</%1$s>',
    		( is_front_page() && is_home() ) ? 'h1' : 'p',
    		esc_url( apply_filters( 'generate_site_title_href', home_url( '/' ) ) ),
    		get_bloginfo( 'name' )
    	);
    });
    #2030256
    Ying
    Staff
    Customer Support

    You are welcome ๐Ÿ™‚

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