Exclude a Custom Post Type
To avoid adding URLs to the Weglot exclusion list, you can disable the translation of a given post type directly with our hooks. In the example below we exclude the built-in page type — replace 'page' with your own Custom Post Type slug.
The two filters do different jobs, and you need both:
weglot_is_eligible_urlmarks the URL as not translatable for the language switcher and thehreflangtags. On its own, it does not stop the page from being translated.weglot_active_translation_before_processis what keeps the page in its original language: a visitor who reaches a translated URL of such a page is redirected to the original one.
<?php
add_filter( 'weglot_is_eligible_url', 'not_authorize_translation' );
function not_authorize_translation( $eligible ) {
if ( get_post_type( weglot_get_postid_from_url() ) === 'page' ) {
return false;
}
return $eligible;
}
add_filter( 'weglot_active_translation_before_process', 'check_page_translation' );
function check_page_translation() {
if ( get_post_type( weglot_get_postid_from_url() ) === 'page' && weglot_get_current_language() !== weglot_get_original_language() ) {
wp_redirect( weglot_get_request_url_service()->get_full_url() );
exit;
}
return true;
}Last updated