admin管理员组

文章数量:1386688

I was following a wp theme developement tutorial but somehow my wp_enqueue_style and wp_enqueue_script not working here is my code

functions.php

<?php
//Adding the css and js files
function gt_setup(){
    wp_enqueue_style('google-fonts','|Roboto+Condensed|Roboto+Slab');
    wp_enqueue_style('font-awesome','.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');
?>

i have added within head in header.php and before body in footer.php

here is my style.css

/*
Theme Name:GTCoding
Author:Godson Thomas
Author URI:www.google
Description:Test theme
Version:1.0
*/

body{
    background:red;
}

js/main.js

alert ("hello from main.js");

header.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=".1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt"
        crossorigin="anonymous">
    <link href="|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>

footer.php

<footer>
 <p>Footer was here</p>
</footer>
<?php wp_footer(); ?>
</body>
</html>

index.php

<?php get_header();?>

<h2>Hi from index.php</h2>

<?php get_footer();?>

i am stuck with this for days..please help i searched the forum but i think my problem is specific..please dont mark this duplicate

I was following a wp theme developement tutorial but somehow my wp_enqueue_style and wp_enqueue_script not working here is my code

functions.php

<?php
//Adding the css and js files
function gt_setup(){
    wp_enqueue_style('google-fonts','https://fonts.googleapis/css?family=Roboto|Roboto+Condensed|Roboto+Slab');
    wp_enqueue_style('font-awesome','https://use.fontawesome/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');
?>

i have added within head in header.php and before body in footer.php

here is my style.css

/*
Theme Name:GTCoding
Author:Godson Thomas
Author URI:www.google
Description:Test theme
Version:1.0
*/

body{
    background:red;
}

js/main.js

alert ("hello from main.js");

header.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/releases/v5.1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt"
        crossorigin="anonymous">
    <link href="https://fonts.googleapis/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>

footer.php

<footer>
 <p>Footer was here</p>
</footer>
<?php wp_footer(); ?>
</body>
</html>

index.php

<?php get_header();?>

<h2>Hi from index.php</h2>

<?php get_footer();?>

i am stuck with this for days..please help i searched the forum but i think my problem is specific..please dont mark this duplicate

Share Improve this question edited Apr 26, 2020 at 2:57 Sash_007 asked Apr 26, 2020 at 2:34 Sash_007Sash_007 74 bronze badges 2
  • thats exactly what i did..the first block of php code that i pasted is from functions.php – Sash_007 Commented Apr 26, 2020 at 2:53
  • what is the html output of the site in the browser? how did you establish the fact that the code 'is not working'? why do you link the same styles directly in header.php? – Michael Commented Apr 26, 2020 at 4:35
Add a comment  | 

1 Answer 1

Reset to default 0

Your action is wp_enqueue_script and not wp_enqueue_scripts. This should fix it. Lemme know how it goes! :)

<?php
//Adding the css and js files
function gt_setup(){
    wp_enqueue_style('google-fonts','https://fonts.googleapis/css?family=Roboto|Roboto+Condensed|Roboto+Slab');
    wp_enqueue_style('font-awesome','https://use.fontawesome/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');
?>

本文标签: wp enqueue scriptWordpress wpenqueuestyle and wpenqueuescript not working