Archived topic
How to remove Javascript?
8 replies · Started by Mr Calvert on November 29, 2020
Can you help me function to remove javascript one by one in this list?
generate-main-js
navigation-search.min.js
back-to-top.min.js
I want to remove that to test effect. I think I not use navigation-search and back-to-top, can you give me function to remove that and CSS of its?
Hi,
You can try dequeuing them with this PHP snippet.
add_action( 'wp_enqueue_scripts', 'tu_remove_menu_scripts', 50 );
function tu_remove_menu_scripts() {
wp_dequeue_script( 'generate-back-to-top' );
wp_dequeue_script( 'generate-navigation-search' );
wp_dequeue_script( 'generate-main' );
}
However, the style for these can't be easily removed without affecting other things in your site as most styles for your site are added in a single stylesheet.
Yes thanks you so much!!!
Can you help me with code css I need remove CSS of search bar and back to top buttom! I was deactive that js so I want remove css too
Can you help me with code css I need remove CSS of search bar and back to top buttom! I was deactive that js so I want remove css too
This is pretty tricky as the search bar and back to top button doesn't have their own stylesheet file.
Their default CSS styles are added within main.css while their non-default styles from Appearance > Customizer is added inline on generate-style-inline-css with again, is combined w/ every other styles.
That said, we can't just dequeue generate-main and generate-style-inline as it will also affect other parts of the site.
However, you can just override them w/ your child theme or custom CSS added on Additional CSS.
And the last question. I was check in blog and category I see it have new js file auto call is list:
jquery.js
infinite-scroll.pkgd.min.js
scripts.min.js
And this javascript I see it call in header: script id='generate-blog-js-extra'
And
script id='generate-classlist-js'
Have any function or turn off that? I want turn off that for testing! Can you help me that function?
You can remove jquery by dequeuing it, wp_dequeue_script( 'jquery' );.
I don't recommend doing this though. Some plugins may be using this library as well.
generate-classlist-js I believe this one is turned off by default. Its only for IE 11 browsers. You can check it on the page source as !-- commented out meaning it doesn't run.
infinite-scroll.pkgd.min.js is only added when you enable infinite scroll on the customizer. You can turn it off it the same way you enabled it on the customizer if you want it removed. generate-blog-js-extra works w/ infinite scroll script and is also removed if you disable infinite scroll.
Yes thanks you so much ^^! All best with you!
Yes thanks you so much ^^! All best with you!
No problem. Glad to be of any help.:)