Exclude a Custom Post Type

To avoid adding URLs to the Weglot exclusion list, you can disable the translation of a Custom Post Type (example: "page") directly with our hooks.

<?php

add_filter('weglot_is_eligible_url', 'not_authorize_translation');
function not_authorize_translation(){
	if (get_post_type( weglot_get_postid_from_url() ) === 'page') {
    	return false;
	}

    return true;
}

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