0

I am trying to add bootstrap.css conditionally via functions.php. I need to apply the bootstrap.css all over the website except about-us template. So in my functions.php

<?php
    function lorem_ipsum(){
         wp_register_style( 'bootstrap', '//maxcdn........css' );

         if( !is_page_template('about-us.php') ) {
            wp_enqueue_style('bootstrap');
        }
}

Its working nice but the problem is: **header.php** also missing the styles from bootstrap but I don't want that. I have tried to add other condition with existing condition, so I can apply bootstrap for the header.php and exclude bootstrap from about-us template. I also checked the wordpress documentations but can't figure it out. I believe, obviously there is a way, I just couldn't figure it out. Have you any suggestion? -Thank you.

6
  • This isn’t how CSS works. You can’t target CSS files at only certain parts of the page. – Jacob Peattie Mar 6 '18 at 14:03
  • Really! Is it impossible? – Shihab Mar 6 '18 at 14:12
  • ...Yeah. You load stylesheets on a page and they apply to elements on the page based on the selectors used. CSS 101. Bootstrap is a CSS framework, it seems strange to me to even want to unload it for part of the page. Why do you need to do this? – Jacob Peattie Mar 6 '18 at 14:14
  • Nice guesses! I am working on a child theme. When I load bootstrap, I m missing some important fields and that is why I m trying to do that. – Shihab Mar 6 '18 at 14:20
  • Why are you loading bootstrap and a parent theme? Bootstrap is intended to be the lowest level of CSS, with any customisations on top. When you already have a parent theme, then a child them and are trying to load a CSS framework you're just going to cause conflicts. You should try to approach this without involving another CSS framework. – Jacob Peattie Mar 6 '18 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.