如何在WordPress主题中添加样式表?

我是wordpress的新手, 我以这种格式在html和css中创建模板

root[folder]
  css[folder]
    style.css
  js[folder]
    script.js
index.html

我将其放入主题目录, 现在是什么???


#1


在WP中, 你需要加入脚本和样式

请参阅WP Codex以获取开始所需的一切

例子

wp_enqueue_style(‘styleCSS’, get_stylesheet_directory_uri()。’path / to / style.css’);

这将放在位于主题中的functions.php中。

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


#2


你必须加入样式表和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

假设你要从google cdn获得主题的最新版本[jquery] [1]。为此, 你必须首先从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' );

来源:

https://www.srcmini02.com/66504.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_40455.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?