• Resolved Georgeba

    (@georgeba)


    I’ve been reading about wp-enqueue and used their example and modified it to my own..
    (This is in my Plugin.php)

    /**
     * Proper way to register and enqueue scripts and styles
     */
    function stepline_stylesheets() {
        wp_register_style( 'stepline-min',  get_template_directory_uri() .'/css/Stepline.min.css', array(), null, 'all' );
        wp_register_style( 'stepline-css',  get_template_directory_uri() .'/css/style.css', array(), null, 'all' );
        wp_enqueue_style( 'stepline-min' );
        wp_enqueue_style( 'stepline-css' );
    }
    add_action( 'wp_enqueue_scripts', 'stepline_stylesheets' );

    For some reason, this isn’t working? I’ve been confused for a while now.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator Jose Castaneda

    (@jcastaneda)

    THEME COFFEE MONKEY

    Hi there!

    Are you using this code in an active theme or is this on an active plugin? If you are using a plugin do note they use different functions to get their directory paths.

    Have you tried deactivating all your plugins to see if that resolves the issue?

    Thread Starter Georgeba

    (@georgeba)

    I did rename my wp-content directory to assets, could that have messed this up?

    Thread Starter Georgeba

    (@georgeba)

    changed it back, deactivated other plugins, switched to another theme. Still not working.

    This is an active plugin

    Moderator Jose Castaneda

    (@jcastaneda)

    THEME COFFEE MONKEY

    So this is a plugin you are developing?

    If it is a plugin then the function you would want to use is plugin_dir_url() not get_template_directory_uri() because the second function will return the active ( or parnt ) theme’s directory. For example, if my CSS file is in the Twenty Sixteen’s css folder I would use:

    wp_enqueue_style( 'neat-o-style', get_template_directory_uri() . '/css/neat.min.css' );

    That would return something like:

    https://superawesomemccool.net/wp-content/themes/twentysixteen/css/neat.min.css

    But if it were in a plugin I would use:

    wp_enqueue_style( 'neat-o', plugin_dir_url( __FILE__ ) . 'css/neat.min.css' );

    And that would return:

    https://superawesomemccool.net/wp-content/plugins/cooliastyles/css/neat.min.css

    Hope that makes sense. ??

    Thread Starter Georgeba

    (@georgeba)

    Thank
    You
    so
    much!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘WP Enqueue Styles – Plugin’ is closed to new replies.