WordPress Theme – Highlight Plugin
March 12th, 2009 | Author: Sunny
When I was trying to post some PHP coding, I found it is not easy to decorate it.. for example, you want the code to be aligned, so that it is user friendly (easy to read). Then you need to handle space for each line. Also, you may want to highlight some keywords. There will be a lot of work, and some programming languages look really similar, but if you want to decorate them, you may have to do it one by one, and it could suck out most of your time.
Fortunately, WordPress has a plugin that helps you to do all the works for you. It is called Highlight, and you can download it and use it as WordPress plugin or just code it within your HTML file. You only need to assign some CSS style such as color for keywords. This is very nice because usually I like to program everything myself, but this really saves me a lot of time. (On the other hand, many things on the web are really useful).
For example,
<?php
if (is_home()) {
echo bloginfo('name');
} elseif (is_404()) {
echo '404 Not Found';
} else {
echo wp_title('');
}
?>
and my CSS Style (which applies the highlight for the code above and below for showcase):
code {
color: #000099;
font: normal "Courier New", Courier, monospace;
white-space: nowrap;
padding: 0 2px;
}
pre code {
display: block;
clear: both;
background: #FDF;
color: #333;
border: solid 1px #ccc;
overflow: auto;
line-height: 140%;
white-space: pre;
width: 470px;
text-align:left;
}
code .comment {
color: #888;
}
code .class, code .rules {
color: #ff00ff;
font-size: 100%;
}
code .value, code .title, code .string {
color: #0000FF;
}
code .tag {
color: #000099;
}
code .keyword {
color: #000099;
}
.html .attribute {
color: #006600;
}
All I have done is just put all my code within <pre><code></code></pre> and it will decorate my code with my CSS style. Isn’t it really easy? yea, you can compare my old posts which I just use <p> and style it, and which still doesn’t look good.
One more thing, if you do not want to use it as plugin, you can just put these two lines of code on your web page (The WordPress plugin will automatically add these two lines to your WordPress blog) :
<script type="text/javascript" src="highlight.pack.js"></script>
<script type="text/javascript">
hljs.initHighlightingOnLoad();
</script>
It is pretty easy, right?
For more information about Highlight, you can visit this Link:
http://softwaremaniacs.org/soft/highlight/en/
I really liked this post. Can I copy it to my site? Thank you in advance.
Original post by Dmitri Gromov
How soon will you update your blog? I’m interested in reading some more information on this issue.
Kelly: I am not sure what you said original post by Dmitri Gromov. I wrote it up myself and not copy from other.
Gary: I want to update more often, but I am working on some projects which slow me down.
Ariana: Sure, but I hope you can reference it.
It’s a pity that people don’t realize the importance of this information. Thanks for posing it.
Hi. I like the way you write. Will you post some more articles?