There are 3 basic ways to show code on your wordpress website posts.
Method 1. Display Code Using The Default Editor
This method is recommended for beginners and users who don’t need to display code very often.Simply edit the blog post or page where you want to display the code. On the post edit screen, add a new code block to your post.
Method 2. Display Code in WordPress Using a Plugin
SyntaxHighlighter Evolved plugin so far is the most popular plugin for display code beautifully on your website and also it is very easy to use. But it may slow down your homepage landing speed as well. For me I don:t write so many codes into my blogs so I pass this method.
Method 3. Display Code Manually Without Plugin
This method is for advanced users because it requires more work and does not always work as intended.First, you need to pass your code through an online HTML entities encoder tool. It will change your code markup to HTML entities, which will allow you to add the code and bypass the WordPress cleanup filters.
Now copy and paste your code in the text editor and wrap it around with <pre>and <code> tags.
Thats all for displalying code on your wordpress posts correctly.