Auto closing PHP tag shortcut for Visual Studio Code

Auto closing PHP tag shortcut for Visual Studio Code

If you are a WordPress developer and work with themes and plugins, you knows that how many times you insert a PHP block into a PHP or an HTML file. It wastes our time. We often feel boring too. So, why shouldn’t we create a snippet for it. I have shown here the way of creating a PHP tag shortcut here.

Step 1:

Go to ‘File Preferences User Snippets

Step 2:

Choose ‘html(HTML)‘ here. We are going to create an HTML snippet.

Step 3:

Write the below code in ‘html.json‘ file.

Code:

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

php tag shortcut

HTML snippet does not support in exact inside of Quotation mark. To enable it, we need to do following steps.

Step 4:

Go to ‘FilePreferencesSettings

Step 5:

Write the below code in ‘settings.json‘ file.

Code:

"editor.quickSuggestions": {
    "comments": false,
    "other": true,
    "strings": true
}

Hurrah! We have done. Now, we are going to check it.

To check,

  • Open a PHP or HTML file in VSCode;
  • Type only ‘php‘, an abbreviation suggestion will appear;
  • Then, press TAB or ENTER button to insert a PHP block;

NOTE: Don’t forget to save changes where needed.

By following this steps, we can create our custom snippet easily.

Leave a Reply

Please Login to comment
  Subscribe  
Notify of