Support » Developing with WordPress » VSCode marks every function as “Undefined function ‘function_name'”

  • Kim

    (@spacewell)


    Hi there,

    I thought this should be easy to fix but it seems I am unable to find a solution.

    I am starting to develop a child theme for a WordPress project.

    In VS Code every function in PHP files is marked with “Undefined function ‘function_name'”

    I am not a specialised WordPress developer but I am assuming these are all WordPress functions. I checked other PHP files (appart from the child theme I’m working on) like files in the parent theme and plugins and this seems to happen on all php files.

    How do I get rid of these messages?

    I tried installing some VSCode plugins like “WordPress Hooks IntelliSense” and “WordPress VS Code Extension Pack” but none of those seem to solve this issue.

    Thanks!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Hi,

    in VS-Code click on the gear on the bottom left corner. Click Settings and search for “stubs” then click on “intelephense” extension and then scroll down to bottom. Click add new item and then add wordpress.

    Thread Starter Kim

    (@spacewell)

    Thanks @benniledl!

    Sadly this just changed the notifications from “Undefined function ‘function_name’” to “Call to unknown function: ‘function_name’”

    Hi, what function exactly are you talking about?

    It works for me.

    Thread Starter Kim

    (@spacewell)

    Just looking at the page.php file in the generatepress theme folder:

    • get_header()
    • do_action()
    • have_posts()
    • the_post()
    • get_footer()

    These don’t get this message (same file). Since they start with “generate” I am assuming the are fuctions from the GeneratePress theme

    • generate_do_attr( )
    • generate_has_default_loop()
    • generate_do_template_part()
    • generate_construct_sidebars()

    In VS Code I’m also getting “phpcs: Request workspace/configuration failed with message: Unable to locate phpcs.” I am unsure if this is related.

    Hi, these generate_ functions are no wordpress functions but from the generatepress theme, you should be able to “load” them into vscode by just opening the file where these functions are defined.

    Thread Starter Kim

    (@spacewell)

    The generate_ functions don’t have this “Call to unknown function… ” message. The other do like get_header().

    I found this as a possible solution but I don’t understand what it means: ” It turns out I needed to open the PHP files in my root folder in order for the WordPress functions to be acknowledged by VScode.”

    Thread Starter Kim

    (@spacewell)

    I figured it out. I had only the child theme and parent theme folders loaded in VS code. When I load the complete WordPress folder the messages are gone.

    Thanks for your help!

    • This reply was modified 4 months, 2 weeks ago by Kim.

    Hi, perfect

    • This reply was modified 4 months, 2 weeks ago by Benni.
    mattcurney

    (@mattcurney)

    Just want to say THANK YOU as Benni’s solution worked great for me. Was struggling with this for a while.

Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.