• Hello, I have tried to enqueue my stylesheet, bootstrap and java script on my website, the function is working but I have seen it people adding array, and true or false at the end of the code and it made me wonder if there is something with the way I did it or it can be better.

    Here is the current code that I am using:

    <?php
    function pixground_styles() {
        // Styles
        wp_enqueue_style('pixground_bootstrap', get_template_directory_uri() . '/bootstrap/css/bootstrap.min.css');
        wp_enqueue_style('pixground_style', get_template_directory_uri() . '/style.css');
        
        // Scripts
        wp_enqueue_script('bootstrap_js', get_template_directory_uri() . '/bootstrap/js/bootstrap.min.js');
        
    }
    
    add_action( 'wp_enqueue_scripts', 'pixground_styles' );
    

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @ferdalkrmn,
    you can read about these here (enqueue_style & enqueue_script )

    Array is used for dependency. If your code depends on some other code/file you call call it in the array. checkout the links i wrote & you’ll see more details.

    True/False are used for showing in the footer or not and many other reasons.

    Hope this helped. Thank You

    Hi @ferdalkrmn,

    You can follow this step for enqueue styles and scripts properly in your theme.

    For scripts
    Usage: wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer );
    1) $handle is a name of the script.
    2) $src is the path of the script file.
    3) $deps if your script is depended on other script or simply use blank array().
    4) $ver if there version for the script you can include here.
    5) $in_footer if you want to show it in footer, by default it is set to false.

    For Styles
    Usage: wp_enqueue_style( $handle, $src, $deps, $ver, $media );
    1) $handle is a name of the style.
    2) $src is the path of the style file.
    3) $deps if your style is depended on other style or simply use blank array().
    4) $ver if there version for the script you can include here.
    5) $media if you would like to load style for specific media type ‘print’, ‘screen’, ‘all’

    Hope this helps you.

    Thread Starter ferdalkrmn

    (@ferdalkrmn)

    Thank you for your replies

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to enqueue style correctly’ is closed to new replies.