我正在关注 this教程。
我正在尝试使用 functions.php
中的 wp_enqueue_scripts
链接通常在 header 中链接的 javascript 和 css 文件。使用我现在所拥有的,只有一个空白的白页正在加载。
函数.php
<?php
// Add scripts and stylesheets
function blogtheme_scripts() {
wp_enqueue_style( 'style', get_template_directory_uri() . '/style.css', array() );
wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/css/bootstrap.min.css', array(), '3.3.6' );
wp_enqueue_style( 'blog', get_template_directory_uri() . '/css/blog.css' );
wp_enqueue_script( 'bootstrap', get_template_directory_uri() . '/js/bootstrap.min.js', array('jquery'), '3.3.6', true );
wp_register_style('OpenSans', 'http://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800');
wp_enqueue_style( 'OpenSans');
}
add_action( 'wp_enqueue_scripts', 'blogtheme_scripts' );
// WordPress Titles
add_theme_support( 'title-tag' );
?>
header.php
我注释掉了 html 链接,因为我认为一旦我在 functions.php
中链接到它们,它们就不应该在那里:
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<!-- Bootstrap core CSS -->
<!--<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">-->
<!-- Custom styles for this template -->
<!--<link href="<?php bloginfo(//'template_directory');?>/blog.css" rel="stylesheet">-->
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<?php wp_head();?>
</head>
该页面只是作为白页加载,我假设这是因为链接有问题,而且我在控制台中没有看到任何错误。
这可能是脚本版本的问题 - 3.3.6
?
最佳答案
如果教程说要在结束正文标记之前调用 wp_head()
,那么教程是错误的。它应该在结束 head
标记之前。
关于javascript - 将 wordpress 中的样式表和脚本与 functions.php 链接起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36075055/