View Full Version : Displaying Code in WP 2.5?
davemcnally
04-26-2008, 02:13 PM
Putting the finishing touches on my redesign, I just noticed that using "<code>" within a an article of my local install (2.5.1) appears to not only invalidate the code but doesn't work either - WP is still parsing the code!
Has anyone had this happen? I'm not using the visual editor either, and don't really want to resort to using a plugin unless it's absolutely necessary.
davemcnally
04-26-2008, 02:23 PM
Update!
Not really sure what was going on there but using "<pre>" instead seems to have fixed it. The code now displays, it validates and even keeps my tabbed spaces within the code. Don't know why "<code>" wasn't working though, all I did was swap that out for "<pre>" and hey presto ;)
BPartch
04-26-2008, 05:50 PM
Hello
Not sure what the deal could be but I use a plugin, this one WordPress WordPress Plugins (http://wordpress.org/extend/plugins/wp-syntax/) it works pretty well, and all you have to do is still use <pre> and add the language to it like so: <pre lang="HTML"><div id="example"></pre>
davemcnally
04-26-2008, 05:57 PM
Hello
Not sure what the deal could be but I use a plugin, this one WordPress WordPress Plugins (http://wordpress.org/extend/plugins/wp-syntax/) it works pretty well, and all you have to do is still use <pre> and add the language to it like so: <pre lang="HTML"><div id="example"></pre>
I actually looked at this plugin amongst a couple of others but I don't want all of the functionality they offer and they seem a bit bloated for my needs, I am only styling the fonts used within code displays and putting a box/border around them so I figured I may as well just style <pre> instead...less hassle and gets me what I want; Code that can be copied, text that is subtle on the page without syntax highlighting and no scrolling-bar boxes :)
SarahG
04-26-2008, 09:01 PM
You said your code was being executed when put between code tags? Were you writing your code as plain code or with encoded less than and greater than signs? As you need to do the latter.
<code></code> is perfectly valid at XHTML Strict, however it is quite unflexible. I've not found a syntax plugin for WP that produces valid, not bloated code (you usually get one or the other). I've now adopted the ordered list method so that I can get line numbers, and use classes for different padding to give some indentation. The syntax isn't highlighted but it's a lot more readable and more importantly, easy to refer to line X in the post.
davemcnally
04-26-2008, 09:07 PM
I was indeed using less than and greater than signs which is why I couldn't understand why it wasn't working. The method you are using sounds like a good one, maybe I will look into using that depending on the amount of code I actually display in articles. For now though, styling the <pre> gives me plenty of control over the formatting as well as producing valid code which should do just fine. Thanks for the help :)
BPartch
04-26-2008, 10:55 PM
I've not found a syntax plugin for WP that produces valid, not bloated code (you usually get one or the other).WP Syntax (linked above) seems to produce valid markup, but I have not looked much at the .css it uses yet.
SarahG
04-27-2008, 12:12 AM
Seems like a few of the plugins have upgraded to better markup. WP Syntax I looked at a couple of months ago and it used tables for the markup (if I'm thinking of the right one), now it uses pre tags, Syntax Highlighter is another that I tried on my site but wasn't happy as it used a textarea to display the code, but now that uses pre tags too.
I'm still puzzled at why Vertexity's code was executed though. If you've got encoded characters then at most the browser can just display them correctly or not correctly, unless something in WordPress is saving them in the database as unencoded? However if pre fixes the problem, presumably you need encoded characters in pre too? So nothing can be converting them whilst saving the content theoretically, else it'd do the same for both.
Bizarre...!
vBulletin® v3.7.2, Copyright ©2000-2008, Jelsoft Enterprises Ltd.