[Resolved] How to add lang attribute to site title?

Home Forums Support [Resolved] How to add lang attribute to site title?

Home Forums Support How to add lang attribute to site title?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #605717
    wekhter

    Hi, I have a site that is majority in English but some portions are in Japanese. In order for the characters to be displayed properly, I need to define the lang attribute to Japanese text strings, ie. <span lang="ja-jp">日本のサイト</span>

    This is simple to do for text within posts/pages, but the site title is also in Japanese. How can I apply the correct lang to the site title in the header?

    #606231
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    So you need to wrap the site title in that <span> element?

    #606388
    wekhter

    @Tom It would be cleanest if I could just add the lang added to h1.main-title but if necessary wrapping the text in a <span> would be OK too.

    #606479
    Tom
    Lead Developer
    Lead Developer

    Try adding this function:

    add_filter( 'generate_site_title_output', 'tu_add_lang_to_title' );
    function tu_add_lang_to_title() {
    	return sprintf(
    		'<%1$s class="main-title" itemprop="headline" lang="ja-jp">
    			<a href="%2$s" rel="home">
    				%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' )
    	);
    }
    #607028
    wekhter

    @Tom

    Perfect! Thanks 🙂 That fixed it.

    #607092
    Tom
    Lead Developer
    Lead Developer

    Awesome, glad I could help 🙂

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