2017-02-06 31 views

回答

0

在WP,你需要enqueue你的脚本和样式

见WP Codex你需要开始

wp_enqueue_style('styleCSS', get_stylesheet_directory_uri(). 'path/to/style.css');

这会在你的functions.php一切位于主题中。

如果不起作用,请检查您的路径。一个很好的帮助是你的浏览器的网络标签,它会告诉你它的404或200.

+0

谢谢你的帮助,你能告诉我如何开始学习wordpress吗? –

+0

最好的方法是访问WP Codex并从第一页开始阅读。安装WP并让它工作,然后看看它附带的一些主题,并通过遵循代码,你很快就会理解它们是如何结合在一起的。 祝你好运! – ste

+0

好的,谢谢你的帮助。 –

0

你必须enqueue无风格的表格和js脚本添加到你的主题。见下面的代码:

function my_theme_scripts(){ 

// Theme's main stylesheet (style.css). 
wp_enqueue_style('twentysixteen-style', get_stylesheet_uri()); 

// custom theme's stylesheet like (font-awesome) 
wp_enqueue_style('fontawesome-stylesheet', get_template_directory_uri() . '/css/font-awesome.css', array(''), '20170106'); 

//add custom scripts to your theme 
wp_enqueue_script('my-custom-script', get_template_directory_uri() . '/js/app.js', array('jquery'), '20170106', true); 
//adding jquery into array means its dependable to jquery 
} 
    add_action('wp_enqueue_scripts', 'my_theme_scripts'); //hooking/adding those scripts and stylesheets to wordpress 

比方说,你想要最新版本[jQuery的] [1]你的主题,从谷歌CDN。为此,你必须首先从wordpress注销已安装的jquery。

// include custom jQuery 
function include_custom_jquery() { 

wp_deregister_script('jquery'); //removing installed jquery 

wp_enqueue_script('jquery','https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', array(), null, true); //adding custom jquery 
} 
add_action('wp_enqueue_scripts', 'include_custom_jquery'); 
+0

是用于激活样式表和脚本文件功能的add_acction函数。 –

+0

是的,这个函数用于激活这些样式表和脚本在这里查看详细信息[链接](https://codex.wordpress.org/Plugin_API/Action_Reference/wp_enqueue_scripts) –

+0

谢谢你的帮助。 –

相关问题