Wordpress: posting beautiful code
Posted Oct 24th, 2008 by David Calhoun in UncategorizedThe last entry I made as some really nicely formatted code, if I do say so myself. It’s because I’ve discovered SyntaxHighlighter by Alex Gorbatchev.
The general code can be used on any HTML and says it’s 100% JavaScript-based. The Wordpress plugin version is based on PHP but looks exactly the same.
All you do when posting code is write your code between these tags: [sourcecode language='css']..[/sourcecode]
(Note: write out the above code, don’t copy and paste, because it preserves the formatting and therefore won’t render the code properly, which is the only way I was able to show the source code as an example here)
The result is something like this:
#button {
font-weight: bold;
border: 2px solid #fff;
}
(via WordPress FAQ)
Update (October 28, 2008)
Wordpress chews up and removes tabs and spaces in your code! To prevent this, you have to click on the “HTML” tab and surround your sourcecode tags with <pre> tags BEFORE you drop in your tabbed/spaced code. This tells Wordpress that it shouldn’t get rid of those spaces/tabs that it apparently hates so much.
Leave a Reply
Categories
- accessibility (1)
- browser bugs (2)
- css (6)
- html (6)
- javascript (9)
- jquery (3)
- mobile (1)
- performance (2)
- php (1)
- regular expressions (1)
- rss (3)
- seo (1)
- Site News (1)
- table (1)
- Uncategorized (4)
- videos (2)
- wordpress (1)
- xml (2)
- yui (0)