Code Blocks with WYSIWYG in blog post

Is it possible to format code in the wysiwyg editor, up to now I use Blockquotes to represent code, but my problem is that it does automatically line breaks, and I don’t want to have random line breaks in my code.

Solutions Collecting From Web of "Code Blocks with WYSIWYG in blog post"

There are several ways to deal with this problem.

You could have a look for some syntax highlighter plugin, those will also bring you coloured text with highlighted keywords etc. pp. This is probably nice, if you use code quite often. I use SyntaxHighlighter Evolved.

If you want to do this by hand, <code> is probably the HTML-element you want to use, just like Stack Overflow does, too. It´s “designed” to be used that way (and understood as code from a semantical view, too).

If you want to prevent line breaks, you can add this to your CSS:

code { white-space: nowrap; }

You have to use this in the text view of the editor though, as the WYSIWYG version would probably strap it out.

You can get around that by defining a shortcode for your code-tag. You will find lots of examples for that around the web.