Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在WordPress中链接外部JS和CSS文件_Javascript_Css_Wordpress - Fatal编程技术网

Javascript 在WordPress中链接外部JS和CSS文件

Javascript 在WordPress中链接外部JS和CSS文件,javascript,css,wordpress,Javascript,Css,Wordpress,我是Wordpress框架的新手。我可以知道如何将外部CSS和JS文件链接到我的Wordpress页面吗?我已经创建了一个新页面,但我想链接一个CSS和JS文件到它 创建新模板或插件是解决方案吗?我对此完全陌生。您可以将文件添加到当前主题中。将css文件添加到header(主题文件夹中的header.php)。并将js文件添加到页脚(主题文件夹中的footer.php)。主题文件夹可在路径wp content/themes/中找到。您可以修改主题的header.php文件,以包含外部JS和CSS

我是Wordpress框架的新手。我可以知道如何将外部CSS和JS文件链接到我的Wordpress页面吗?我已经创建了一个新页面,但我想链接一个CSS和JS文件到它


创建新模板或插件是解决方案吗?我对此完全陌生。

您可以将文件添加到当前主题中。将css文件添加到header(主题文件夹中的header.php)。并将js文件添加到页脚(主题文件夹中的footer.php)。主题文件夹可在路径wp content/themes/

中找到。您可以修改主题的header.php文件,以包含外部JSCSS文件。Header.php位于wp content>themes>current active theme>Header.php中


在编辑器中打开它,并在
标记之间包含指向外部或文件的链接。

取决于您是否要添加CSS或JS条件。如果希望将它们包含在所有文件中,只需使用主题文件夹的functions.php页面,然后添加:

            function your_scripts() {
                    wp_register_script('yourscriptname', '/PATH/TO/YOUR/SCRIPT.js', false);
                    // This registers your script with a name so you can call it to enqueue it
                    wp_enqueue_script( 'yourscriptname' );
                    // enqueuing your script ensures it will be inserted in the propoer place in the header section
            }
            add_action('wp_enqueue_scripts', 'your_scripts');
            // This hook executes the enqueuing of your script at the proper moment.
对于样式表,按以下方式进行操作:

            function your_css() {
                wp_register_style( 'nameofyourCSSsheet', '/PATH/TO/YOUR/STYLESHEET.css' );
                wp_enqueue_style( 'nameofyourCSSsheet' );
            }
            add_action( 'wp_enqueue_scripts', 'your_css' );
            // same hook is used to enqueue CSS sheets

您不需要创建插件或新模板来链接到现有Wordpress主题中的文件

正如建议的那样,如果打开themes header.php,在结束标记之前,可以插入指向文件位置的链接

CSS文件通常位于主题文件夹中: wp content/themes/your_theme/style.css

您可以使用以下Wordpress函数调用样式表:

请查看以下Wordpress Codex部分以获取信息:

我知道这条线索有点过时,但也许其他人会发现它很有用

包含外部CSS和JS文件的正确方法是在源参数上使用和

例如,要在主题中包含google字体,您需要执行以下操作:

wp_enqueue_style( 'twentytwelve-googlefonts', esc_url_raw( 'http://fonts.googleapis.com/css?family=Titillium+Web:600,300,200' ), array(), null );

使用“插入页眉和页脚”wordpress插件。它为你做了所有的工作!只需将插件中应该包含的内容粘贴到插件的标题部分。

您不需要购买任何插件,只需打开WordPress主题根目录中的function.php文件即可。只需插入这个函数PFB,只需更改目录,对于js,您不需要连接单独的文件,因为您可以使用footer.php并在script标记中插入js代码,它将准确工作

add_action( 'wp_enqueue_scripts', 'radliv_child_enqueue_styles' );
    function radliv_child_enqueue_styles() {
    wp_enqueue_style( 'custom-css-style', get_template_directory_uri() . '/inc/assets/css/custom.css' );
} ;

您只需在
header.php
中加载文件,就像您通常使用静态html页面那样。