How to post code correctly on a blog


I came across an unpleasant snag. It turns out that when you put php, SQL and other code in the body of a WordPress post, it is reformatted in a certain way and when it is copied into the real enviroment, the code may not be executed.
 
To prevent this from happening, you need to use the pre tag:
<pre>There could be code here without reformatting and spacing</pre>

You can also use textarea (obsolete):

When you want to place HTML so that it is not executed by browsers, you need to code all brackets, quotation marks and other nonsense into html characters. WordPress does this automatically if you paste the code into the wizard editor. For example, like this:

<a href=”http://skobki.com” rel=”nofollow”>Unindexable link</a>

In the sources this expression looks like this:

&lt;a href=”http://skobki.com” rel=”nofollow”&gt;Unindexable link&lt;/a&gt;

Plugins and modules for code output. There are many of them and they are popular. However, I do not recommend their use – why overload the site? For convenience, you can configure css-styles for pre and add a button in a visual editor, but no more. WordPress is not a very fast engine, so it is loaded with meaningless plugins 🙂
 
That’s such a sausage. In the future, I pledge to put the code in the right way and you advise :mrgreen:

This entry was posted in FAQ (en), Programming (en), Wordpress (en). Bookmark the permalink.

Leave a Reply

🇬🇧 Attention! Comments with URLs/email are not allowed.
🇷🇺 Комментарии со ссылками/email удаляются автоматически.