• Resolved wovawefo

    (@wovawefo)


    Hi

    I am trying to equeue a style in my plugin, but it produces a Server Error with code 500. I’ve been testing the code and as soon as I comment out add_action line, the site goes back to normal.

    I tested the code by pasting it into functions.php file of the the child theme and it worked there, but as soon as I move it to the plugin, the site crashes.

    Here is the code:

    add_action( 'wp_enqueue_scripts', 'enqueue_plugin_styles' );
    function enqueue_plugin_styles() {
    	wp_enqueue_style( 'main-search-header', get_bloginfo('url') .'/wp-content/plugins/uppskriftabok-custom/css/main-search-header.css' );
    }

    I tried to get the url by an absolute path (http://etc etc), through bloginfo() and of course plugins_url(). None works in the plugin (does through the theme though), the problem doesnt seem to be there.

    Some info on the plugin:
    It is just a plugin where I add any extra functionality to the theme later on. I am just starting out with it, I only have shortcode defined in it that inserts an html block into the page. It all works, I am trying to add the stylesheet that contains the formatting for the html block that is inserted…

    Anyone with any idea? I have even increased the wp memory limit…

    Would be greatful for some ideas.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Hi wovawefo

    Try prefixing the function name, the name could allready exist in another theme or plugin.

    from the handbook:

    All files, variables, and functions should be prefixed with a unique identifier. Prefixes prevent other plugins from overwriting your variable values or accidentally calling your functions. It will also prevent you from doing the same. Adding the initials of your plugin name or your name is a good start.

    https://developer.wordpress.org/plugins/the-basics/best-practices/#prefix-everything

    Can you post the complete plugin file here.

    Thread Starter wovawefo

    (@wovawefo)

    Wow thx sooo much keesiemeijer!

    This worked! I had tried name changes with all sorts of suffixes, but apparently the names were too generic and that suffixes dont work.

    I am sure I will always remember from now on 🙂 Prefixes are king!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘500 server error after enqueuing style in plugin’ is closed to new replies.