Site logo

Archived topic

How to add lang attribute to site title?

5 replies · Started by wekhter on June 21, 2018

Viewing posts 1–6 of 6

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?

Hi there,

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

@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.

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' )
	);
}

@Tom

Perfect! Thanks :) That fixed it.

Awesome, glad I could help :)

This archived topic is closed to new replies.