skip to Main Content

I am looking for function for WooCommerce which change meta title text in non-active tab. Anybody know how can I do it? I find this JS code but it does not work in themes function.php file:

$(function() {
  var message = "Don't forget us";
  var original;

  $(window).focus(function() {
    if (original) {
      document.title = original;
    }
  }).blur(function() {
    var title = $('title').text();
    if (title != message) {
      original = title;
    }
    document.title = message;
  });
});

2

Answers


  1. You can put that script into a tag <script></script> in the footer.php file wich should be located in your theme (don’t forget to actually duplicate this file inside your child theme)

    EDIT: Also make sur to have JQuery in your frontend

    Login or Signup to reply.
  2. The following goes into functions.php

    add_action('wp_head', function () {
        ?>
        <script>
            (function () {
                var message = "Don't forget us"
                var original
    
                jQuery(window).on("focus", function () {
                    if (original) {
                        document.title = original
                    }
                }).on("blur", function () {
                    var title = jQuery("title").text()
                    if (title != message) {
                        original = title
                    }
                    document.title = message
                })
            })()
        </script>
        <?php
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search