Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1403666

    Hello together
    I have received from a supporter for the plugin:
    Page scroll to id Version 1.7.7
    received the following message:
    For the color of the target term, since you don’t have the links in your top menu, you’ll need to use javascript.
    Can you add some js code in your page?
    For example, you can add the following in your theme/child-theme footer.php template
    in a new line right before the closing body tag (</body>):
    <script>
    (function($){
    $(window).on(“load”,function(){
    setTimeout(function(){
    var _hash=window.location.hash;
    if(_hash){
    var targetElem=$(_hash);
    if(targetElem.length){
    targetElem.addClass(“highlighted-term”);
    }
    }
    },100);
    });
    })(jQuery);
    </script>

    Now I can not figure out where to insert this?

    Can you help me with this
    and write me where this code was inserted?

    thanks in advance
    kind regards
    Franz

    #1403781

    In almost all cases it is sufficient to have these custom scripts in the footer – sometimes it is necessary to set a priority for these inserts. But for all jQuery scripts, they must be loaded after jQuery is already loaded.
    ( maybe your timing is a bit to fast – i did not test your script – but if 100 does not work try 300)
    ( PS – this comes to child-theme functions.php )

    function your_custom_script_insertion() { 
    ?>
    <script type="text/javascript">
    (function($){
    	$(window).on('load',function(){
    	setTimeout(function(){
    		var _hash=window.location.hash;
    			if(_hash){
    				var targetElem=$(_hash);
    				if(targetElem.length){
    					targetElem.addClass('highlighted-term');
    				}
    			}
    		},100);
    	});
    })(jQuery);
    </script>
    <?php 
    }
    add_action('wp_footer', 'your_custom_script_insertion');

    However, I do not understand the meaning of the script.
    because only if you click a link with hash, the hash is also indicated above in the Url. If you click several hash links, then all get this class one by one.

    #1403784

    Thanks a lot
    Guenni007

    this works great

    then this request can be closed

    kind regards
    schweg33

    #1403789

    Hi Franz,

    Great, I’m glad that @guenni007 could help you out. I’ll close this thread for now then, please open a new thread if you should have any further questions or problems.

    Best regards,
    Rikard

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Insert script’ is closed to new replies.