Viewing 12 replies - 1 through 12 (of 12 total)
  • Thread Starter Generosus

    (@generosus)

    More Info:

    The PHP code snippet provided here did not work either. We have an idea why it didn’t work. We’ll probably need a modified version of your plugin’s widget code. ??

    Plugin Author edo888

    (@edo888)

    Hi,

    You can use js and add this before GTranslate widget code is executed:

    
    // todo: write is_mobile function
    if(is_mobile())
        window.gt_translate_script = true;

    When that variable is set the mentioned script will not be loaded.

    Thanks! ??

    Thread Starter Generosus

    (@generosus)

    Hi @edo888,

    To clarify, where do we add or embed your code? Immediately above your widget code?

    Thank you!

    Thread Starter Generosus

    (@generosus)

    Hey @edo888,

    So, we had to “decrypt” your above answer ??

    We added the code snippet provided below to our functions.php file, but it’s not working. The external file is still loading on our site when viewed with a mobile device. Confirmed by running either Lighthouse or WebPageTest.

    As a test case, we also changed “true” to “false”, but still not working.

    What are we doing wrong? Can you kindly expand your previous answer?

    Thank you!

    ———————

    add_action( 'wp_head', 'is_mobile' );     
    function is_mobile() {
        echo '<script>
            if(is_mobile())
        	window.gt_translate_script = true;
        </script>';
    }
    • This reply was modified 1 year, 12 months ago by Generosus.
    Thread Starter Generosus

    (@generosus)

    Hi @edo888,

    Update:

    Well, we tried just about every imaginable code snippet, etc. available to us (using your tip) to achieve our goal without success.

    So, for now, we have to live with this condition and hope you will add this as a feature to your plugin.

    Specifically, add a new “Device” settings feature with three options: All, Desktop Only, and Mobile Only. When using the Mobile Only option please consider using the “wp_is_mobile” function which includes tablets (e.g., iPads, etc.).

    You can do it ??

    Thank you!

    Plugin Author edo888

    (@edo888)

    Hi,

    It is very basic javascript without any PHP involved, do not overcomplicate it.

    You need to do some actions in your theme so that your HTML source code output looks like this:

    <html>
    <head>...</head>
    
    <body>
    <script>
    // todo: write is_mobile function
    if(is_mobile())
        window.gt_translate_script = true;
    </script>
    
    ...
    <!-- GTranslate code goes here -->
    ...
    </body>
    </html>

    is_mobile is a javascript function which you need to write yourself, it simply detects the mobile device. I’m sure you can find many examples if you search it.

    Thanks! ??

    Thread Starter Generosus

    (@generosus)

    Hey @edo888,

    Again, thank you. We are definitely not trying to complicate things.

    We tried what you recommended as follows:

    1. Created the script noted below (Reference)

    <script>
    $(function() {      
        let is_mobile() = window.matchMedia("only screen and (max-width: 760px)").matches;
    
        if(is_mobile()) {
        window.gt_translate_script = true;
        }
     });
    </script>

    2. Added the above script to the Space before </body> of our website.

    3. We did not add the widget code to the Space before </body> of our website (as you implied above) because your own plugin provides a warning not to do so.

    4. Result: Not working

    So … rather than going back and forth and if it’s easy for you — as the developer and owner of this plugin — can you share the code snippet and/or detailed code that will enable your plugin on Desktop only?

    Also, shouldn’t your code say “false” not “true” (i.e., window.gt_translate_script = false;) when detecting a mobile device? We do not want to load your script on Mobile devices only Desktops.

    Thank you for your help and patience ??

    Cheers!

    Plugin Author edo888

    (@edo888)

    Hi,

    Your code is still complicated. If you just check the window width to detect mobile device then this is much simpler:

    <script>
    if(window.innerWidth < 760)
        window.gt_translate_script = true;
    </script>
    

    You need to make sure the HTML structure looks like this as mentioned earlier:

    <html>
    <head>...</head>
    
    <body>
    <script>
    if(window.innerWidth < 760)
        window.gt_translate_script = true;
    </script>
    
    ...
    <!-- GTranslate code goes here -->
    ...
    </body>
    </html>

    Inserting it right before </body> as you did is wrong. Make sure that the code is before GTranslate code, it doesn’t matter where in the body tag you insert, you need to make sure it is executed before GTranslate scripts.

    If it still does not work, then post your website address, so I can check what you did.

    Thanks! ??

    Thread Starter Generosus

    (@generosus)

    Hi @edo888,

    It worked. Thank you.

    Your code was added to the Space before </head> section of our site.

    Again, thank you!

    Plugin Author edo888

    (@edo888)

    You are welcome! If you have a moment, please share your experience about the support you have received by writing a review: https://www.ads-software.com/support/plugin/gtranslate/reviews/#new-post

    Thanks! ??

    Thread Starter Generosus

    (@generosus)

    Done!

    Plugin Author edo888

    (@edo888)

    Thank you! ??

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘How Can We Load GTranslate on Destkop Only?’ is closed to new replies.