我一直在遵循wp主题开发教程,但不知怎么的,我的wp\\u enqueue\\u风格和wp\\u enqueue\\u脚本不起作用。这是我的代码
功能。php
<?php
//Adding the css and js files
function gt_setup(){
wp_enqueue_style(\'google-fonts\',\'https://fonts.googleapis.com/css?family=Roboto|Roboto+Condensed|Roboto+Slab\');
wp_enqueue_style(\'font-awesome\',\'https://use.fontawesome.com/releases/v5.1.0/css/all.css\');
wp_enqueue_style(\'style\',get_stylesheet_uri());
// wp_enqueue_script($handle,$src,$deps,$ver,$in_footer);
wp_enqueue_script(\'main\',get_theme_file_uri(\'/js/main.js\'),NULL,\'1.0\',true);
}
add_action(\'wp_enqueue_script\',\'gt_setup\');
?>
我在页眉中添加了“在页眉内”。php和页脚正文之前。php
这是我的风格。css
/*
Theme Name:GTCoding
Author:Godson Thomas
Author URI:www.google.com
Description:Test theme
Version:1.0
*/
body{
background:red;
}
js/主要。js公司
alert ("hello from main.js");
标题。php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt"
crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Roboto|Roboto+Condensed|Roboto+Slab" rel="stylesheet">
<link rel="stylesheet" href="style.css">
<title>GTCoding</title>
<?php wp_head();?>
</head>
<body>
<header>
<h1>Header here</h1>
</header>
页脚。php
<footer>
<p>Footer was here</p>
</footer>
<?php wp_footer(); ?>
</body>
</html>
索引。php
<?php get_header();?>
<h2>Hi from index.php</h2>
<?php get_footer();?>
我被这件事困扰了好几天。。请帮助我搜索了论坛,但我认为我的问题是具体的。。请不要标记此副本
最合适的回答,由SO网友:Joel Hager 整理而成
你的行动是wp_enqueue_script
而不是wp_enqueue_scripts
. 这应该可以解决它。让我知道怎么回事!:)
<?php
//Adding the css and js files
function gt_setup(){
wp_enqueue_style(\'google-fonts\',\'https://fonts.googleapis.com/css?family=Roboto|Roboto+Condensed|Roboto+Slab\');
wp_enqueue_style(\'font-awesome\',\'https://use.fontawesome.com/releases/v5.1.0/css/all.css\');
wp_enqueue_style(\'style\',get_stylesheet_uri());
// wp_enqueue_script($handle,$src,$deps,$ver,$in_footer);
wp_enqueue_script(\'main\',get_theme_file_uri(\'/js/main.js\'),NULL,\'1.0\',true);
}
add_action(\'wp_enqueue_scripts\',\'gt_setup\');
?>