Support » Plugin: Highlight Search Terms » No highlighted found terms in page templates

  • Resolved sadhaka

    (@sadhaka)


    If I search for a term, the term is highlighted in the results, but not in the page if that page is a template.

    I notice the console error:

    SyntaxError: Cannot declare a const variable twice: 'hlst'.

    Any ideas what might give rise to this?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi, does your theme invoke wp_footer() twice?

    Thread Starter sadhaka

    (@sadhaka)

    I don’t think so. There’s only one instance of <footer [etc]> in the source.

    Thread Starter sadhaka

    (@sadhaka)

    If this gives you any clue, in the source of the “offending” template (when it has been the result of a search, and the query string has been duly appended, such as ?hilite=zebra), the content of the script is basically repeated, so it looks like:

    <script id='hlst-extend-js-after'>
        /* Highlight Search Terms 1.6.1 ( RavanH - http://status301.net/wordpress-plugins/highlight-search-terms/ ) */
        const hlst = function() {
            window.hilite(["zebra"], ["#groups-dir-list", "#members-dir-list", "div.bbp-topic-content,div.bbp-reply-content,li.bbp-forum-info,.bbp-topic-title,.bbp-reply-title", "article", "div.hentry", "div.post", "div.wp-block-query", "#content", "#main", "div.content", "#middle", "#container", "div.container", "div.page", "#wrapper", "body"], true, true)
        };
        window.addEventListener('DOMContentLoaded', hlst);
        window.addEventListener('post-load', hlst);
        /* Highlight Search Terms 1.6.1 ( RavanH - http://status301.net/wordpress-plugins/highlight-search-terms/ ) */
        const hlst = function() {
            window.hilite(["zebra"], ["#groups-dir-list", "#members-dir-list", "div.bbp-topic-content,div.bbp-reply-content,li.bbp-forum-info,.bbp-topic-title,.bbp-reply-title", "article", "div.hentry", "div.post", "div.wp-block-query", "#content", "#main", "div.content", "#middle", "#container", "div.container", "div.page", "#wrapper", "body"], true, true)
        };
        window.addEventListener('DOMContentLoaded', hlst);
        window.addEventListener('post-load', hlst);
        </script>

    So the function gets called twice and the same variable gets declared twice.

    But maybe you realised all that.

    I can’t think why the function should be repeated like that.

    Hmmm, okay thanks for showing me the code snippet. That certainly explains the error.

    But I cannot explain why that code would be repeated there. It is as if the plugin gets initialized twice but that is not possible…

    In the original post, you said:

    …but not in the page if that page is a template.

    Which theme? Which template? Or is that a customized template?

    Thread Starter sadhaka

    (@sadhaka)

    I found the problem. It was my template – I had inadvertently called wp_head() twice.

    It had nothing to do with your excellent plugin – sorry to have troubled you.

    Ow.. that would indeed run the wp_enqueue_scripts action twice, which explains the double inline script. Didn’t think of that possibility…

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