4

Visual studio code user snippets not working for php. Have restarted VS code and the PC. Still does not work.

User snippet code:

enter image description here

No snippet shows up:

enter image description here

Visual studio code version:

enter image description here

1
  • What does "not working" mean? Please share all details in text form, not hidden in screenshots Commented Mar 26, 2024 at 9:16

3 Answers 3

13

Put it in the html snippets file. It is what php files use unless you are inside <?php ?> tags.

Sign up to request clarification or add additional context in comments.

Comments

4

As far as I know VSC won't pick up your php snippets even though your file might end in .php , what you have to do is insert manually <? php ... ?> and afterwards your snippets should start work.

If you don't want to enter <? php ... ?> manually every time you can create a global snippet "Preferences-->User Snippets-->New Global Snippets File. Save the new file to something like "global.code-snippets" and then add your php snippet. Maybe something like that.

"php tag": {
"prefix": "php",
"body": [
  "<?php",
  "  ${1:code}",
  "?>"
],
"description": "php tag"}

2 Comments

This was exactly my problem. I created a snippet: "PHP envelope": { "prefix": "php", "body": "<?php $0 ?>", "description": "Enter PHP mode." } that wouldn't work in php.json but now works in global snippets.
Perfect, I had the same problem. I didn't know about global snippets.
1

Configuring Visual Studio Code for PHP development from here:

  • Download and install PHP Debug extension from Visual Studio marketplace.
  • In VS Code command panel: press F1 > type ‘install ext’ and select ‘Install Extensions’. enter image description here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.