In this article:
- Using the WordPress Code Editor to edit an individual block
- Using the Code Editor to edit the entire post or page
- Why does my code gets removed from the WordPress Code Editor?
- How to Edit Other WordPress Code
- How do I edit Widget HTML?
- Where else can I add Custom Code in WordPress?
- How do I edit HTML in WordPress theme code?
The Gutenberg editor gives you a visual interface that makes it easy for you to compose a page or post. However, many people still edit their content using the WordPress code editor. Fortunately, the code editor is still present within the Gutenberg editor. You can edit the entire post or page as code, or you can edit individual blocks as code. We will show you how to use the code editor in the Gutenberg editor using a sample post.
Looking for an alternative to the Gutenberg Editor? Try our WordPress Page Builder that uses a different approach to WordPress Blocks to help build your website with ease! Otherwise, here are the steps needed to continue this tutorial using WordPress with the current WordPress Editor:
Using the WordPress Code Editor to edit an individual block
- Open the page or post and click on the block that you wish to edit with the code editor. A toolbar will appear above the block.
- On the far right you will see 3 vertical dots. Click on the dots. A pop-up menu will appear. Click on the option labeled Edit as HTML.
- You will then see the block displayed in code. Make your changes or additions to the block.
- If you wish to see the block in the visual editor after the changes, simply click on the 3 vertical dots again and then click on option labeled Edit Visually.
- Once you are finished, you will need to click on the Update or Publish options in the top right corner of the editor in order to save your changes.
Using the Code Editor to edit the entire post or page
- Open the page or post that you wish to edit.
- In the top right hand corner next to the icon that looks like a gear you will see 3 vertical dots. Click on the dots.
- Here you will see the options for Visual Editor or Code Editor. By default, the Visual Editor is selected. Click on the Code Editor to place the editor in that mode.
- Make your changes to the page or post. If you’d like to return to the visual editor, click the Exit code editor link in the upper right of the screen.
- Click on the Update or Publish button in the top right hand corner in order to save your changes.
Why does my code gets removed from the WordPress Code Editor?
Sometimes code will get removed when switching between visual and code views. This happens when the editor doesn’t know what to do with the code – it can’t interpret it. If this happens, it might be easier to use a Custom HTML block.
How to Edit Other WordPress Code
How do I edit Widget HTML?
As of the WordPress 5.8 release, widgets now display as blocks. Navigate to Appearance > Widgets in the dashboard. Hover over the widget you’d like to edit and then click the 3 dots that appear on the right side of the toolbar. If it is possible to edit the HTML of that widget, you will see the Edit as HTML link. Please note that not all widgets will have this option.
Where else can I add Custom Code in WordPress?
If you’re adding CSS code to use on more than one page, consider using the Customizer. Any code added to the Custom / Additional CSS panel is available to use across the entire site.
There are some types of code will not function if added to a page or post, like tracking codes. These generally need to be in the header or footer. There are tracking code plugins available to get the code in the correct location.
How do I edit HTML in WordPress theme code?
It is not possible to edit a theme’s code from the WordPress editor. You can make changes to a theme from the dashboard by going to Appearance > Theme Editor, but we do not recommend it. If you want to make code changes to a WordPress theme you should use a Child Theme. Otherwise theme updates could override or break your changes.
This concludes our tutorial on how to use the WordPress Code editor / Gutenberg editor. If you wish to learn more about using the WordPress Gutenberg editor, please see our article on publishing content with the Gutenberg editor.
200+ Design Templates + 1 Kick-ass SuperTheme
6 WordPress Plugins + 2 Essential Services
Everything you need to build and manage WordPress websites in one Central place.