Error Log – One error that is repeating itself

Hi,

So on this site http://www.a1autocare.net/ it has an error log.

With this error in; [22-Jul-2019 09:15:22 UTC] PHP Warning: Missing argument 2 for wp_register_style(), called in /home/a1autocare/public_html/wp-content/mu-plugins/dequeue-bootstrap.php on line 2 and defined in /home/a1autocare/public_html/wp-includes/functions.wp-styles.php on line 125

The MU Plugin folder has one file in which i have pasted below – if it gets deleted the error stops but the menu goes virtual instead of horizontal.

<?php
wp_register_style( 'bootstrap' );?>

The log is one error that is repeating itself. I have tested it and every time someone visits a page on the site it adds 4 more lines to the file.

The file grows in size until eventually it’s too big and we have issues with the site.

Any help is appreciated

  • Adam Czajczyk
    • Support Gorilla

    Hello allanlove

    I hope you’re well today!

    The “wp_register_style()” function is called incorrectly in your mu-plugin:

    wp_register_style( 'bootstrap' );

    This function requires at least two attributes to be used where the first one is “handle” (basically, a “name” to be used as a reference for the style in scripts) and a style source. This one is missing style source so it’s actually doing nothing there.

    Assuming that your bootstrap style file is called “bootstrap.min.css” and is in the parent theme folder in a CSS sub-folder of it, the correct line would be

    wp_register_style( 'bootstrap',  get_template_directory_uri() . 'css/bootstrap.min.css' );?>

    That being said, I checked your site and the “bootstrap.min.css” file seems to be already loaded on site anyway so this mu-plugin shouldn’t even be necessary. Does removing it affect the site in anyway (breaks it)?

    Best regards,

    Adam

  • allanlove
    • The Bug Hunter

    Hi,

    Thanks for the response.

    The bootstrap file is called “dequeue-bootstrap.php”

    When deleting the file it makes the main menu go vertical instead of horizontal and look really bar. So I am guessing it is needed but not sure how to fix the error.

    Regards

  • Adam Czajczyk
    • Support Gorilla

    Hello allanlove

    By “bootstrap style file name” I didn’t mean the your mu plugin filename but the name of an actual bootstrap CSS file name.

    The “wp_register_style()” is used incorrectly in your code inside the “dequeue-bootstrap.php” file. I must say I’m not even sure about that entire solution because it’s kind of “internally contradictory”.

    The “dequeue-bootstrap.php” file name suggests that the code inside is meant to actually remove bootstrap CSS from site but the theme seems to need it (it’s already using it). Additionally the “wp_register_style()” function is not for removing but for adding styles from external file.

    I suppose the fact that removing the mu plugin file changes the site is a kind of “side-effect” of the error but I’m not sure what was the exact intention behind that. Putting that aside though, if removing the file breaks the site, the solution for the error is to fix the code inside the file:

    1) wp_register_style() function needs two parameters, where the second (missing one) is the path of the CSS stylesheet file; try using this code for in your plugin instead the one that is there currently:

    <?php
    wp_register_style( 'bootstrap', get_template_directory_uri() . 'css/bootstrap.min.css' );

    2) if that doesn’t help either, you might need to change it further; according to docs, the “wp_register_style()” should never be called “outside of the action” so if above doesn’t work, try this:

    <?php
    add_action( 'wp_enqueue_scripts', 'register_my_bootstrap_styles' );
    function register_plugin_styles() {
    wp_register_style( 'bootstrap', get_template_directory_uri() . 'css/bootstrap.min.css' );
    wp_enqueue_style( 'bootstrap' );
    }

    Kind regards,

    Adam