How to add custom css/js to just one page in WordPress?

前端 未结 1 473
伪装坚强ぢ
伪装坚强ぢ 2020-12-17 02:21

I made a separate html file with custom css and js files. I want to integrate it into a wordpress site. I can copy and paste the body part of the html, however I don\'t know

相关标签:
1条回答
  • 2020-12-17 02:26

    When you will add the page from the WordPress back end, using Pages->Add new from the menu, you have to give a title and using that title (also possible using slug and id) you can check is_page('page title here') and then can add JavaScript and css files, like

    add_action( 'wp_enqueue_scripts', 'addcssAndScripts');
    function addcssAndScripts()
    {
        if ( is_page('page-title') )
        {
            wp_enqueue_script( 'your_script' );
            wp_enqueue_style( 'your-style' );
        }
    }
    

    paste this code in your functions.php and check wp_enqueue_style and wp_enqueue_script for better understanding of these functions and usage, also is_page and wp_enqueue_scripts if needed.

    0 讨论(0)
提交回复
热议问题