0

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.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');
?>

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.com
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.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>

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

  • thats exactly what i did..the first block of php code that i pasted is from functions.php – Sash_007 Apr 26 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 Apr 26 at 4:35
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.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');
?>
| improve this answer | |
  • thanks..that worked..cheers! – Sash_007 Apr 27 at 0:58
  • Glad I could be of help! :) – Joel Hager Apr 27 at 1:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.