skip to Main Content

is there any way to including bootstrap into our custom plugin without affecting theme ccs/js files?

I have include a php file with included bootstrap library at the head. when I activate my plugin something in my homepage changing

2

Answers


  1. Bootstrap has predefined styles for some tags like buttons, nav, … which is why it will override your theme style for these elements.

    You could add an id to your body tag (for example: id="something") and then add #something in your theme’s css rules in front of the styles overridden by bootstrap so that your theme’s css will take precedence.

    #nav {} would become #something #nav {}

    See this as it’s similar: How can I override Bootstrap CSS styles?

    Login or Signup to reply.
  2. go to functions.php in root directtory of your project and try to add this

    
        function monthem_register_assets(){
            wp_register_style('bootstrap','https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css');
            wp_register_script('bootstrap','https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js');
            wp_enqueue_style('bootstrap');
            wp_enqueue_script('bootstrap');
        }
    
    add_action('wp_enqueue_scripts','monthem_register_assets');
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search