You can utilize the page or post slug to determine the English pages. I am presenting a sample code block below that can be followed to replace the existing lang attribute with a new one. Please note that this process requires proficiency in coding.
/**
* Modify language attributes for specific pages and posts.
*
* @param string $output HTML attributes for the <html> tag.
* @return string Modified HTML attributes for the <html> tag.
*/
function my_custom_language_attributes( $output ) {
// Define an array of page and post slugs to modify.
$page_slugs = array( 'my-page-slug', 'my-post-slug' ); // Add any additional page or post slugs here
// Check if the current page or post is in the defined array of slugs.
if ( is_page( $page_slugs ) || is_single( $page_slugs ) ) {
// Get the current language.
$lang = get_bloginfo('language');
// Set the desired language.
$new_lang = 'en-US';
// Replace the current language with the new language in the HTML attributes.
$output = str_replace('lang="' . $lang . '"', 'lang="' . $new_lang . '"', $output);
}
// Return the modified HTML attributes.
return $output;
}
// Hook the function to the language_attributes filter.
add_filter( 'language_attributes', 'my_custom_language_attributes' );