最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

linking stylesheets and scripts with functions.php

programmeradmin1浏览0评论

I am following along with this tutorial.

I am trying to link the javascript and css files that are usually linked in the header using wp_enqueue_scripts in functions.php. With what I have now, only a blank white page is loading.

functions.php

<?php
// Add scripts and stylesheets
function blogtheme_scripts() {
    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 );
}

add_action( 'wp_enqueue_scripts', 'blogtheme_scripts' );

// Add Google Fonts
function blogtheme_google_fonts() {
    wp_register_style('OpenSans', '+Sans:400,600,700,800');
    wp_enqueue_style( 'OpenSans');
}

add_action('wp_print_styles', 'blogtheme_google_fonts');

// WordPress Titles
add_theme_support( 'title-tag' );

?>

header.php

I commented out the html links because I figured they weren't supposed to be in there once I linked to them in 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=".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=".7.2/html5shiv.min.js"></script>
    <script src=".4.2/respond.min.js"></script>
  <![endif]-->
  <?php wp_head();?>
</head>

The page just loads as a white page, I'm assuming it's because something is wrong with the linking, and I don't see any errors in the console.

Could it be an issue with the versions of the scripts - 3.3.6?

I am following along with this tutorial.

I am trying to link the javascript and css files that are usually linked in the header using wp_enqueue_scripts in functions.php. With what I have now, only a blank white page is loading.

functions.php

<?php
// Add scripts and stylesheets
function blogtheme_scripts() {
    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 );
}

add_action( 'wp_enqueue_scripts', 'blogtheme_scripts' );

// Add Google Fonts
function blogtheme_google_fonts() {
    wp_register_style('OpenSans', 'http://fonts.googleapis/css?family=Open+Sans:400,600,700,800');
    wp_enqueue_style( 'OpenSans');
}

add_action('wp_print_styles', 'blogtheme_google_fonts');

// WordPress Titles
add_theme_support( 'title-tag' );

?>

header.php

I commented out the html links because I figured they weren't supposed to be in there once I linked to them in 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/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/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn/respond/1.4.2/respond.min.js"></script>
  <![endif]-->
  <?php wp_head();?>
</head>

The page just loads as a white page, I'm assuming it's because something is wrong with the linking, and I don't see any errors in the console.

Could it be an issue with the versions of the scripts - 3.3.6?

Share Improve this question edited Mar 18, 2016 at 4:39 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Mar 18, 2016 at 3:19 ewizardewizard 1018 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

There are no errors in your code shown above and I've double checked to see it working correctly in a fresh WP install. It should not be the cause of your errors.

A white screen is usually any error but it's not printed to the screen.

Take a look at the DEBUG section of the codex to change that. This might need to be dropped into your wp-config.php.

// allow debugging 
defined( 'WP_DEBUG' ) or define( 'WP_DEBUG', true );

// log errors to wp-content/debug.log
defined( 'WP_DEBUG_LOG' ) or define( 'WP_DEBUG_LOG', true );

// show errors on screen
defined( 'WP_DEBUG_DISPLAY' ) or define( 'WP_DEBUG_DISPLAY', true );
发布评论

评论列表(0)

  1. 暂无评论