0

Hi guys i have google and searched and tested codes i finded here but nothing works, i have wordpress site and i want to make some css and js dont load in the first page because some plugins puts the css and js in the first page but i dont need it here...

For example: <link rel='stylesheet' id='cleaning-services-shop-css' href='/wp-content/themes/stadperfekt/css/shop.css' type='text/css' media='all' />

i dont need it in first page so i want it not to load only in first page...

If somebody knows it will be really helpful. Thanks

1 Answer 1

0

If you're not wanting something to load on the front page, wrap it in a !is_front_page() check. !is_front_page() will check if the current page is your site's base URL (regardless of whether you have it set to a static page or the posts page in your settings).

Example:

<?php
if ( !is_front_page() ) : ?>
     <link rel="stylesheet" href="style.css"/>
<?php
endif; ?>

Please remember not to directly edit plugin/theme files, they will get overwritten whenever they get updated and all your work will be gone. For themes, create a child theme instead, and for plugins you'll need to check their documentation to see if they have a hook/filter to remove their css/js links.

Source: WordPress Docs

9
  • Hi. thanks for trying to help me, but i think the code you wrote will show that css in front page, that style.css already showing on all pages, but i want to by code make it not load on first page..? If you understand me :/ Nov 22, 2023 at 15:38
  • No, that code will hide it on the front page and should work fine. The ! means not. I might try using a wp_enqueue though instead.
    – rudtek
    Nov 22, 2023 at 16:25
  • the problem is the css already runig true i dont know wich file in wordpress, where should i put the code then? if i put it on header nothing happens, i want to hide the css already runig thrue some file.. is it possible? Nov 22, 2023 at 16:38
  • if you look in functions: code: wp_enqueue_script('bootstrap', CLEANING_SERVICES_JS_URL . '/vendor/bootstrap.min.js', array('jquery'), '', true); how to disable it on only front page. or style: wp_enqueue_style('bootstrap', CLEANING_SERVICES_CSS_URL . '/vendor/bootstrap.min.css', '', null); Nov 22, 2023 at 16:41
  • @MilanAndjelkovic Yes you wrap the code you want to hide on the front page with the !is_front_page() if statement. If you've already found the wp_enqueue_script() function that enqueues the file, you can wrap that statement with !is_front_page() instead.
    – YourManDan
    Nov 22, 2023 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.