Is there a way to make Visual Studio Code recognize HTML syntax in PHP files
Solution 1
As far as I can tell, it does. Take a look at this php
file I have created in VS Code (no extensions), with HTML inside the file with syntax highlighting for both languages.
There is a button (It should say the word PHP) in the bottom right corner of the screen that allows you to switch the syntax highlighting and autocompletion to another language, and while this does temporarily turn off PHP syntax, it will allow you to code in HTML a lot easier.
Solution 2
You can install this plugin intellisense-plugin
Solution 3
You can enable html support in any language by adding the following to your settings.json
file:
"emmet.includeLanguages": {
"your-language": "html",
"rust": "html",
"php": "html",
"javascript": "html",
}
Related videos on Youtube
thatemployee
Updated on September 14, 2022Comments
-
thatemployee over 1 year
I am using Visual Studio Code on a Mac to work on WordPress applications.
Is there a way to make Visual Studio Code recognize HTML and use it's features (mainly autocompletion) inside PHP files?
I've searched for this answer before but just get told to Go to Visual Studio Code Settings:
File >> Preferences >> User Settings
// Place your settings in this file to overwrite the default settings { // Configure file associations to languages (e.g. "*.extension": "html"). These have precedence over the default associations of the languages installed. "files.associations": {"*.php": "html"} }
But doing this makes you lose all PHP support and autocompletion.
I wish Microsoft would realize that PHP developers commonly use PHP and HTML together when creating applications/websites. I would love to use VS Code instead of the magnificent but expensive PHP storm if possible.
-
Patrick Q over 6 years"PHP developers commonly use PHP and HTML together" I would actually advise against that whenever possible.
-
thatemployee over 6 years@PatrickQ Yeah because it's totally possible to not use HTML inside template.php files. Common now.
-
thatemployee over 6 years@JonStirling Then maybe Microsoft shouldn't try and claim they have 'Fantastic PHP support'
-
Jonnix over 6 years
99% of existing code bases for client work in agencies do not.
Nope. -
Jonnix over 6 yearsWell if you will come up with ludicrous statements... anyway... moving on.
-
thatemployee over 6 years@Stefan Ah yes, maybe I shouldn't have added my opinion at the end and just left it as a question only. Didn't think people on StackOverflow were so sensitive, lesson learned. Thanks for the insight.
-
-
Sam Joshua over 2 yearsThankyou, So much It helped it 2021
-
m3.b over 2 yearsdoesn't work for me, nothing changes.