1

I don't know why I'm having this issue. I'm new to wordpress and I am following along with a 'freecodecamp' tutorial(youtube) on how to make a custom wordpress theme from scratch.

In the video, the instructor is enqueueing his style sheet using the functions.php file. Here is the exact code he is using...

Click here for code image

<?php
    function followandrew_register_style() {
        wp_enqueue_style('followandrew-bootstrap', get_template_directory_uri() . "/style.css", array(), '1.0', 'all');

    }
        add_action('wp_enqueue_scripts', 'followandrew_register_style' );
?>

Click here for error image

Visual Studios is prompting this error as soon as I write out the commands...

"Undefined function 'wp_enqueue_style', and undefined function 'add_action'.

I am including "wp_head()" inside my front-page.php to output the stylesheet.

Everything else is working fine. I am able to see my basic html setup when posting in inside the "front-page.php". My wordpress is connected correctly and I have access to the backend admin.

If I hardcode the path to the style sheet inside of front-page.php, it works fine.

So basically, any functions or commands I try to run inside the functions.php file are coming back undefined!

  • but have you tried to execute the code? Visual studios may be not aware of that function as it's hidden somewhere in the wordpress core. Your code looks ok really – Andrei Filonov Feb 18 '21 at 21:31
  • The coding appears correct. Maybe VisualStudio is not detecting the WP environment. Test with `print_r(defined('ABSPATH'));` The result will be 1 when in the WP scope. If it is 0, the functions.php is not being loaded. – Nadal Feb 18 '21 at 21:34
  • I tried print_r(defined('ABSPATH')); and it comes back with 1. I even did a simple echo "Does this output to the actual page?" ... and it does! – AlbertEinstein Feb 18 '21 at 22:00
  • I'm just going to leave it alone for now, just kinda weird that I'm getting the error in the first place. Thanks for replying back guys! – AlbertEinstein Feb 18 '21 at 22:07

1 Answers1

0

Nevermind, it looks like everything is working fine. I just had the wrong source path for the custom css link.

VS code is still displaying the undefined error but everything is working.

Best 5 hours Ive ever wasted :)

  • Though the file path may have been incorrect, that should not have caused notices of undefined WP functions. Heck I've entered the wrong file URI numerous times and never got a notice. However you may want to consider using `get_stylesheet_uri()` which will find the correct theme file as long as it is named `style.css` See details at https://developer.wordpress.org/reference/functions/get_stylesheet_uri/ – Nadal Feb 18 '21 at 22:48