Bootstrap 4 Optimization

You just make a big mistake. use this guideline. header.php <link rel=”stylesheet” href=”https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css” integrity=”sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm” crossorigin=”anonymous”> You also made a mistake calling js file. Frist needs jQuery then popper.js then bootstrap and the big mistake is you call all of them in the header file, that’s why when the page is loaded it takes time to … Read more

JavaScript: TypeError: xyz is not a function after upgrading WordPress

According to @fuxia comment: Solution is removing jQuery included by WordPress just before register/enqueue custom jQuery (see https://stackoverflow.com/a/27048128). So if you include some jQuery on your own, then add wp_dequeue_script(‘jquery’); wp_deregister_script(‘jquery’); just before register/enqueue custom jQuery script in wp_enqueue_scripts action. Or if you want jQuery included by WordPress just remember, that it’s in no-conflict mode … Read more

Cannot get custom javascript to execute on page

Try this. add_action ( ‘wp_head’, ‘custom_script_hook’); function custom_script_hook() { ?> <script type=”text/javascript” src=”https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js”></script> <?php $output=”<script> jQuery(document).ready(() => { $(“div#tm-extra-product-options”).click(() => { console.log(“it working!”) }); }); </script>”; echo $output; }

Add text to Text Widget using Javascript

Where are you using document.write? Inside the text widget? If so, it should write text inside that widget, just like you want. document.write injects data where it’s encountered. So if you’re using it outside the document body it will produce unexpected results (like overwrite the document, in most cases). **Update, add this in your text … Read more

convertEntities() used before it is defined

The convertEntities function was defined in utils.js, but if you use script concatenation this file would be included after it is needed. Because it was in a try-catch clause, the error was not (always) noticed. The solution is to include the convertEntities function before this code is loaded. In WordPress 3.1 this is now included … Read more

Document.body.scrollTop in WordPress

It would seem that something in WordPress causes a virtual revert to a standards that require cross-browser compatibility, making the same code not work inside and outside WordPress. However, with some code to handle browser-differences (and still avoiding using libraries), the following is what viewport.js looks like now: function height() { if( typeof( window.innerWidth ) … Read more

PHP or JS for header image rotator?

Using PHP sends less code to the end user. (a single img tag instead of all the javascript logic). If you enable browser caching settings correctly (try W3 Total Cache), once the end user has “seen” all the images, those will all be in their cache, so on the “long tail” JavaScript vs. PHP solution … Read more