how to properly enqueue styles and scripts in PHP/WordPress

后端 未结 2 1531
栀梦
栀梦 2020-12-21 21:19

I\'m new to WordPress/PHP and I\'m trying to create a theme, during a tutorial it\'s saying to use the wp_enqueue_style/script to load css/js files however for some reason I

相关标签:
2条回答
  • 2020-12-21 21:37

    You can do that :

        wp_enqueue_script( 'blog', get_template_directory_uri() . '/js/blog.js', array('jquery'), true );

    0 讨论(0)
  • 2020-12-21 21:43

    Yes your code for adding css and js in WordPress is correct but you need to give Unique Name to each css and js

    Try below code :

    function rixcy_scripts() {
        wp_enqueue_style( 'bootstrap-css', get_template_directory_uri() . '/css/bootstrap.css', array(), '' );
        wp_enqueue_style( 'blog', get_template_directory_uri() . '/css/blog.css' );
        wp_enqueue_script( 'bootstrap-jquery', get_template_directory_uri() . '/js/bootstrap.js', array('jquery'), true );
        wp_enqueue_script( 'blog-js', get_template_directory_uri() . '/js/blog.js', array('jquery'), true );
    
    }
    
    add_action( 'wp_enqueue_scripts', 'rixcy_scripts' );
    
    0 讨论(0)
提交回复
热议问题