Wordpress automatically adds <pre> tags when pasting code, how to stop it?

I am presently learning PHP and Linux simultaneously. And I want to blog my notes not only for my future reference, but also because it could help others.

I just noticed an issue with Wordpress - - it automatically adds pre/pre tags in the background (HTML-side I mean, in the visual editor I see the code's background highlighted) as soon as I paste some code, be it HTML, PHP etc.

I have searched a lot, and could find nothing about this. Looks like nobody thinks this as an issue, or it's something too easy to resolve. Either way, I am on the other side of things. So, please help me out.

I want Wordpress to stop highlighting the code like that. I Just want it to keep whatever I paste as it is.

Topic pre php html Wordpress

Category Web


There is probably a pre tag somewhere in the included template files. If you are working with a local copy - try doing a search for <pre> and see what files contain it.

I have had similar issues with the wordpress wysisyg - and just edited the template file outright.

Of course, this only is doable with the self-hosted wordpress, and not a blog on wordpress.com


I would like to recommend the Syntax Highlighter Evolved plugin for Wordpress. I use it on my own site and it is awesome. In fact a lot of the programming blogs you read will use it also. It supports a large number of coding formats, line numbers, alternate line colors, autocopy to clipboard, etc.

WP plugin

Authors Website

Example from my website


The only way to keep it the way you paste it is by switching to the HTML tab - this will show you the raw code as you formatted it. Wrapping code in tags is also a good idea because it tells the browser that the code is literally 'precomposed', and it therefore won't render it. In terms of WP actually altering your code it is likely it will change characters such as '<' for their HTML entity equivalent, meaning browsers will render it as text rather than code.

Why exactly do you want to keep it without the tags? It shouldn't alter that much.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.