• Resolved webmark487

    (@webmark487)


    Hi,

    How can you prevent private pages and pages that are not published (draft) from not being translated? So that as word usage is not increased.

    Thx in advance and best regards

    Markus

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor Edson Galina Fortes

    (@glx77)

    Hi @webmark487 ,

    thanks for your message, it’s help. You can solve your issue adding this code on your website using code snippet or directly on your file (mu plugin, functions.php, …):

    add_action('pre_get_posts', 'custom_weglot_translated_search_redirect');
    function custom_weglot_translated_search_redirect() {
        global $post;
        if ($post) {
            $post_status = get_post_status($post->ID);
            if (!function_exists('weglot_get_original_language') || !function_exists('weglot_get_current_language')) {
                return;
            }
            if (($post_status == 'draft' || $post_status == 'private') && !is_admin() && weglot_get_original_language() != weglot_get_current_language()) {
                wp_redirect(weglot_get_full_url_no_language(), 301);
                exit;
            }
        }
    }
    
    add_filter('weglot_button_html', 'custom_weglot_translated_search_no_selector');
    function custom_weglot_translated_search_no_selector($button_html) {
        global $post;
        if ($post) {
            $post_status = get_post_status($post->ID);
            if (($post_status == 'draft' || $post_status == 'private') && !is_admin()) {
                return '';
            }
        }
        return $button_html;
    }

    Don’t hesitate if you need more help

    Regards

    Thread Starter webmark487

    (@webmark487)

    ah, cool

    does this snippet also handle private/draft posts and products (woocommerce), and not only pages?

    Plugin Contributor Edson Galina Fortes

    (@glx77)

    Hi @webmark487 ,
    hope you’re fine ?
    yes in my example i just take the post staus without check the post type so it would work with product or post not only for pages.

    If you want to check the post type you can add a condition using

    get_post_type($post->ID)

    Regards

    Thread Starter webmark487

    (@webmark487)

    thank you !!

    Plugin Contributor Edson Galina Fortes

    (@glx77)

    Hi @webmark487 ,

    thanks to have close the topic ;).
    If you appreciated my help and if you have 2 minutes to help us, it would be awesome if you could give us a?[good ??] review on WordPress:
    —->?https://www.ads-software.com/support/plugin/weglot/reviews/

    It’s really useful for us ??

    And of course, if you need anything, don’t hesitate to ask me.

    Regards

    Thread Starter webmark487

    (@webmark487)

    May I ask an additional question please.

    How can I check, that this script works and do I have to delete all the urls of the private/draft pages in weglot now?

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.