You may have a page or post in WordPress or just a non-WordPress page – a regular website, where you want to display HTML code, PHP code or other code. The problem? If you just put the code in your web page or in WordPress, the code will just execute and the code will not be displayed on your website. So, how can you work around this? We will use name codes to display a symbol. The symbol will not be a keyword key, so the browser will not interpret the display and your server will not execute the code, if executable.Majority of tutorials will state you will have to use name codes on every special character. This is not correct. You will only need to use name codes, if the code contains a starting syntax and you only need to use name codes for the first character of the starting syntax.

Example

The following is PHP code where there is a starting syntax:

<?php echo "Hello World!"; ?>

The following does not have a syntax:

echo "Hello World!";

In the second above example, your server will not execute the code because the server thinks the web page contains text and not code, because the code is not defined by the PHP syntax.

Now, when we want to display the code on our web page, we only need to touch the first character of the syntax, which will be a <. The name code for < is <. So, for the PHP hello code example, example #1, the code you would use to display it on your web page is:

 <?php echo "Hello World!"; ?>

Example for HTML Code

Let’s say you want to display a link on your website, because it’s an affiliate link and you want people to use it, but you don’t want the code to be executed by the browser interpreting the code. The code is:

 <a title="Affiliate Link" href="http://www.yourdomain.com/affiliate-link" target="_blank">Affiliate Link</a>

You would use the following instead:

<a title="Affiliate Link" href="http://www.yourdomain.com/affiliate-link" target="_blank">Affiliate Link</a>

You’ll notice in this example, the name code, <, is used for each HTML element. This is because each element in HTML will be interpreted by the browser.