Display HTML Code in WordPress Post
In WordPress posts if we write any HTML codes in Text editor, the code will not be displayed.
Instead of code, WordPress, sends the HTML code as it is.
The web browser compiles the code to display its output. Hence the code will not visible to the reader.
To avoid this, follow these steps
- Write code in visual editor.
- Select the code.
- Change format to ‘preformatted’
Now, this will decode the HTML code. If you click on text editor and see the HTML or Javascript codes, it will now be in decoded format.
So, the web browser does not compile it and the output will display the code as it is.
Decode HTML Tags for Pre/Code
The alternate method is to use online HTML decode services available. Google for HTML decode and you will get many matching online decoders. Then follow these steps.
- Copy paste your HTML or Javascript code to decoder.
- Get it decoded.
- Copy the resulting HTML code.
- Paste it in text editor.
- Wrap it with <pre> tag
Now, click on preview page and you could see the actual HTML codes. If you are managing a HTML or Javascript tutorial blog, then it is inevitable to include code snippets in your pages. In that cases, these tips will be more useful.
External Reference: Stackoverflow discussion on same topic.