javascript - 将 wordpress 中的样式表和脚本与 functions.php 链接起来

标签 javascript php html css wordpress

我正在关注 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/

相关文章:

html - QTextBrowser的setSource崩溃

html - 如何在html5中禁用dragend动画

javascript - 如何在 Node 5.6.0 环境中运行 Node 6 npm 包?

javascript - Ajax 将参数发送到 php 页面时不执行任何操作

php - 如果满足条件,Composer 会自动加载包

php - 在没有 formhelper 的情况下使用 CakePHP 检索 POST 数据

javascript - 如何动态调用javascript函数

javascript getOwnPropertyNames 方法

php - 如何使用 distinct 分隔层次结构值

javascript - AngularJs 中的路由更改后,HTML5 相机不会关闭