I'm testing out the new TwentyTwentyTwo theme for WordPress 5.9. I can see that when I enter a post, on the right side I have the option to either Edit or Create New Templates.
In edit mode, it brings us into the edit view of that template (which kinda reminds me of a reusable block in a way..)
But how do we "edit and save" PHP code for these templates? Like loops, actions, do_actions, etc... I don't see the templates being auto generated in my Visual Studio Code environment anywhere....
I'm testing out the new TwentyTwentyTwo theme for WordPress 5.9. I can see that when I enter a post, on the right side I have the option to either Edit or Create New Templates.
In edit mode, it brings us into the edit view of that template (which kinda reminds me of a reusable block in a way..)
But how do we "edit and save" PHP code for these templates? Like loops, actions, do_actions, etc... I don't see the templates being auto generated in my Visual Studio Code environment anywhere....
Share Improve this question edited Mar 1, 2022 at 14:12 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked Feb 28, 2022 at 18:32 klewisklewis 8991 gold badge14 silver badges29 bronze badges1 Answer
Reset to default 0But how do we "edit and save" PHP code for these templates? Like loops, actions, do_actions, etc... I don't see the templates being auto generated in my Visual Studio Code environment anywhere....
You don't, these are block templates, not PHP templates. When in the filesystem in a theme they are plain .html
files, and when you modify or create them in the user interface they're saved in the database.
In order to run PHP code in these templates you would need one of the following:
- a custom block that renders in PHP
- a custom shortcode inserted via a shortcode block
This is the same as asking how to run PHP inside a posts content, and the solutions are the same. Custom blocks and shortcodes.