Posting code in wordpress
If you have ever wanted to post some source code or a code snippet in WordPress this is a sure read. Earlier today I posted an article that I wanted to post some SQL statements in. These statements were pretty complex with lots of single and double quotes. WordPress did an excellent job of screwing these up for me. The code snippet would not work when my readers copied it and tried it themselves. Luckily I caught this before 1000’s of my (non existent) readers could have seen it.
If WordPress has caused you some grief with formatting your code, I’m sure you have searched high and low on the internet for a plugin or even a new editor that would not mess up your text formatting. I searched the web for a few minutes myself and didn’t really find what I wanted. I did come across quite a few sites that mentioned putting your quotes and double quotes as well as other characters in ASCII codes format. This seemed to be difficult for me to read through many lines of code and replace each little character that was going to possibly cause me a problem.
Replacing key characters with ASCII code keeps WordPress for formatting the text. On the output side the text is displayed correctly and is not displayed in ASCII code. The only problem I found with this solution was I had to manually figure out what to replace as well as look up the ASCII code and then type it in. My solution? A text to ASCII converter. Within seconds I found a website that would take my source code text and output ASCII codes. I simply take my entire section of source code, not just the characters that cause me problems, and I convert it to ASCII codes. I paste this into my post as if it were my code snippet (it technically is, just in ASCII code format). I then use code brackets around it in my WordPress WYSIWYG editor and everything looks great.
Here is the website I used: Text to ASCII Converter Site
Hope this helps you as it has helped me.