I have been using Github Gists and the Codebox application to save and share my code snippets, but I wanted to start posting them here on my website to make them easier to find and update. I wasn’t quite happy with any of the existing code syntax highlighting plugins for WordPress, so I built my own, Sunburst Code Prettify.
Sunburst Code Prettify uses Google Code Prettify, a JavaScript module and CSS file that allows syntax highlighting of source code snippets. This plugin contains the CSS file for the Sunburst theme syntax highlighting formatting. You can find the other available syntax highlighting themes available in the Code Prettify Theme Gallery
Download from WordPress.org
HTML Example
<div class="span4">
<h2>Reset via Normalize</h2>
As of Bootstrap 2, the traditional CSS reset has evolved to make use of elements from <a href="http://necolas.github.com/normalize.css/" target="_blank">Normalize.css</a>, a project by <a href="http://twitter.com/necolas" target="_blank">Nicolas Gallagher</a> that also powers the <a href="http://html5boilerplate.com" target="_blank">HTML5 Boilerplate</a>.
The new reset can still be found in <strong>reset.less</strong>, but with many elements removed for brevity and accuracy.
</div>
<!-- /.span -->
CSS Example
body {
text-align: left;
color: #222;
font-size:1.6em; /* 16 px equiv */
line-height: 1.5em; /* 24px equiv */
position: relative;
background-color: #22252E;
background-image: url(../halfbaked/images/linen.png);
background-repeat: repeat;
padding-top: 4.5em;
}
PHP Examples
if (have_posts()) : while (have_posts()) : the_post();
$ideas_posts = $wpdb->get_results(
"SELECT * FROM $wpdb->posts
WHERE post_status = 'draft'
AND post_type = 'post' ORDER BY post_date DESC");
foreach ($ideas_posts as $memberpost):
JavaScript Example
require(["jquery", "jquery.alpha", "jquery.beta"], function($) {
//the jquery.alpha.js and jquery.beta.js plugins have been loaded.
$(function() {
$('body').alpha().beta();
});
});
Ruby Example
# Formats date either as ordinal or by given date format
# Adds %o as ordinal representation of the day
def format_date(date, format)
date = datetime(date)
if format.nil? || format.empty? || format == "ordinal"
date_formatted = ordinalize(date)
else
date_formatted = date.strftime(format)
date_formatted.gsub!(/%o/, ordinal(date.strftime('%e').to_i))
end
date_formatted
end