Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 2 replies, has 2 voices.

Last updated by Andreas W. 3 months, 2 weeks ago.

Assigned support staff: Andreas W..

Author Posts
October 15, 2021 at 2:10 pm #9798733

simoneP-25

Hi there,

I have created my own sitemap with the encoding in functions.php.

I just have a unique issue.
I need it in English only, but when I "Update" the page in French or other languages the sitemap capture value in French etc.

How to get values for the English only?

My code below:

// SITEMAP VIDEO
function video_sitemap() {
$videoSitemap = '<?xml version="1.0" encoding="UTF-8"?>';
$videoSitemap .= '<urlset xmlns="hidden link" xmlns:video="hidden link">';

// DEFINE DEFAULT LANGUAGE
do_action( 'wpml_switch_language', 'en' );

// DEFINE CONTENTS
$videoContents = get_posts(array(
'numberposts' => -1,
'orderby' => 'date',
'post_type' => array('page'),
'order' => 'ASC',
'suppress_filters' => false
));

foreach( $videoContents as $videoContent ) {
setup_postdata($videoContent);

// DEFINE VALUE
$get_machine_video = get_field('get_machine_video');
//$get_machine_video = get_field('get_machine_video',apply_filters( 'wpml_object_id', $post->ID, 'post', TRUE,'en' ));

// DEFINE SEMANTIC
if($get_machine_video):

$videoSitemap .= "<url>\n";
$videoSitemap .= '<loc>' . get_the_permalink($post->ID) . '</loc>' . "\n";
foreach($get_machine_video as $get_machine_video_content):

$get_machine_video_name = $get_machine_video_content['get_machine_video_name'];
//$get_machine_video_name = get_field('get_machine_video_name',apply_filters( 'wpml_object_id', $post->ID, 'post', FALSE,'en' ));

$videoSitemap .= "<video:video>\n";
$videoSitemap .= '<video:title>'. $get_machine_video_name .'</video:title>' . "\n";
$videoSitemap .= "</video:video>\n";

endforeach;
$videoSitemap .= "</url>\n";

endif;
}
$videoSitemap .= '</urlset>';
$fp = fopen(ABSPATH . "agv-video.xml", 'w');
fwrite($fp, $videoSitemap);
fclose($fp);
}
add_action('publish_page','video_sitemap');

October 15, 2021 at 2:18 pm #9798763

simoneP-25

Exactly.

I have the correct value for:

<video:title>'. $get_machine_video_name .'</video:title>

But if I update the page in French I will get the value in French.

I need the value in English only, regardless of whether you update pages in other languages.

Thank you

October 16, 2021 at 9:43 am #9802085

Andreas W.
Supporter

Languages: English (English ) German (Deutsch )

Timezone: America/Lima (GMT-05:00)

Hello,

It appears that this behavior is expected, when runing a multilingual website, but in the case of WPML only if using a different domain per language:

https://wpml.org/errata/yoast-seo-sitemaps-work-different-when-using-different-domains/

This means, if you use directories as the language URL format Google validates this as one sitemap in /sitmap that contains all the pages in all the languages.

More details here:
https://wpml.org/documentation/related-projects/using-wordpress-seo-with-wpml/#translate-sitemaps

Best regards
Andreas

The topic ‘[Closed] Get value from for the default website language only’ is closed to new replies.