WordPress Plugin – FV Code Highlighter
Posted by Frank on September 10, 2008The main subject of this blog will be web development and feature some interesting articles and tutorials ranging from PHP and jQuery to HTML and CSS. The problem I was facing when I built this theme was the lack of an awesome code highlighter plugin. I just couldn’t find one that was working for me.
I thought maybe more people were looking for a plugin that simply publishes codes that look great. I started to write my own, and the FV Code Highlight plugin was born and now open for the public. The features are plain and simple, read on.
Description
This plugin supports the highlighting of PHP, HTML, CSS and more. The default tag-highlighter color scheme uses the same colors Adobe’s Dreamweaver is using. This makes it easy for your visitors to recognize what type of codes you wrote. These colors can be changed to your liking in the WP Admin section of your blog.
Features
- Easy to use
- Renders PHP, HTML, CSS, XML, Javascript and more
- Customizable look of the code boxes
How to use this plugin?
- Upload the folder
fv-code-highlighter
to the/wp-content/plugins/
directory. - Make sure the cache dir
/wp-content/plugins/fv-code-highlighter/cache
is writable by your webserver. - Activate the plugin through the ‘Plugins’ menu in WordPress.
- Choose your preferred settings on the options page: WP Admin > Appearance > Code Highlighter.
- Place your code between
<pre lang=codetype>...</pre>
tags to use the highlighter.
Example
General Code
<pre>...</pre>
:
extension String { |
|
var banana : String { |
|
let shortName = String(characters.dropFirst(1)) |
|
return "\(self) \(self) Bo B\(shortName) Banana Fana Fo F\(shortName)" |
|
} |
|
} |
|
|
|
let bananaName = "Jimmy".banana |
CSS Code
<pre lang="css">...</pre>
:
/* Comment */ |
|
@import url("main.css"); |
|
h3, .head2 { |
|
font-family: "Sans-Serif"; |
|
font-weight: bold; |
|
color: #336699 !important; |
|
} |
|
@media screen, print { |
|
pre { margin: 0px 10px 10px; } |
|
h1 { font-size: 14px; padding-top: 10px; } |
|
} |
(x)HTML Code
<pre lang="html">...</pre>
:
<style type="text/css">headline {font-size: 24pt;}</style> |
|
<!-- Comment --> |
|
<td> |
|
<a href="link">Plain Text </a> |
|
<img src="image" alt="" width="15"> |
|
<form action="action.php" style="border: 1px solid #eee;"> |
|
<input type="submit" value="Press Me"> |
|
</form> |
|
<p>Text</p> |
|
</td> |
|
<script type="text/javascript"> |
|
if (document.getElementById('hi')) { |
|
window.alert('Hello World!'); |
|
} |
|
</script> |
JavaScript Code
<pre lang="javascript">...</pre>
:
/* JavaScript */ |
|
function displayWords(arrayWords) |
|
{ |
|
for (i=0; i < arrayWords.length; i++) { |
|
// inline comment |
|
alert("Word " + i + " is " + arrayWords[i]); |
|
} |
|
} |
|
var tokens = new Array("Hello", "world"); |
|
displayWords(tokens); |
PHP Code
<pre lang="php">...</pre>
:
<?php |
|
/* Connect to a MySQL database using driver invocation */ |
|
$dsn = 'mysql:dbname=testdb;host=127.0.0.1'; |
|
$user = 'dbuser'; |
|
$password = 'dbpass'; |
|
|
|
try { |
|
$conn = new PDO($dsn, $user, $password); |
|
$sql = 'SELECT name, color, calories FROM fruit ORDER BY name'; |
|
|
|
/* @var array $row */ |
|
foreach ($conn->query($sql) as $row) { |
|
displayFruit($row['name'], $row['color'], $row['calories']); |
|
} |
|
} catch (PDOException $e) { |
|
echo 'Connection failed: ' . $e->getMessage(); |
|
} |
|
?> |
Bugs
If you find any bug in the latest version of this plugin, I hope you’d be so kind to tell me about it. This will only improve the plugin, which is better for the users! You can do this on the bug reports forum.
Help Needed?
If you need any help, or have problems with this plugin, please create a post on the support forums.
Plugin Info
AUTHOR: Frank Verhoeven
AUTHOR URL: https://frankverhoeven.me/
CURRENT VERSION: 2.1.2
WORDPRESS VERSION: 4.0+
PHP VERSION: 7.0+
Download
DEMO: Live Demo
DOWNLOAD: FV Code Highlighter
Support
If this plugin is helpful to you, please consider supporting it! You can help it’s development by making a small donation, or promote it by putting a link to this page on your site. Appreciate it!
Pingback: Interesting Code Highlighters for blogs and websites - Talk about Deal – Blog
Pingback: >> essencious << » Blog Archive » Code Snippets Plugins
NeatHighlighter.com is a very easy to use highlighter and highlights code in standard colors
I love this Plugin, It’s great…
The colors are great, and its working fine in PHP code…
The only think I will suggest you to add are one or two functions…
A Copy All Button and why not, a Print Button
Well that are just ideas from others plugin…
(Sorry my english, I am from Argentina)
Are you working in more codes like JS C++ and more?
Pingback: Useful plugin for code | GreyBlogs.com - Themes
Pingback: 12 WP Plugins to Display and Highlight Code within your Blog | JT's World
Pingback: Du code dans un article Wordpress | Canal 31
Great plugin. Cannot wait for PHP to start working. Also is there anything in the works for bash?
Pingback: 5 Best Code Highlighting Plugins | ReviewPk
Pingback: done with blog setup | iPhone Diary
Okay, the fatal error is fixed now. Apparently I had an extra folder called trunk which caused this (just re-downloaded and there isn’t any trunk folder in that one.. odd..).
Still isn’t working though.. 🙁
I would love to use this plugin, but for some reason it’s giving me a fatal error on activation (Fatal error: Cannot redeclare class FVCodeHighlighting in /…/wp-content/plugins/fv-code-highlighter/FVCodeHighlighter.php on line 13)..
Any idea on what’s going wrong?
Great plugin! Any news on the js support?
Pingback: Booto’Design » Blog Archive » 12 Wordpress Plugins to Display and Highlight Code
Pingback: 12 Wordpress Plugins to Display and Highlight Code within your Blog : Speckyboy Design Magazine
Pingback: Plugin FV Code Highlighter | Webseiten-Infos.de
Pingback: « Wordpress Plugin: FV Code Highlighter - Eligio : EH-Lee-Hee-Oh
great plugin, work perfectly on wordpress 2.7. thanks
GREAT PLUGIN!
Wow… thanks God ! I found You Franks… FV COde Highlighter it’s So helpfull 🙂
how can i put javascript theme in this, now days its more javascript then html.. can we have javascript option too please..
As soon as PHP is fixed (it now still has some bugs), I can easily add JavaScript support very easy. So it will come soon 🙂
Pingback: Four Top Wordpress Code Highlighters Reviewed
hi!
i can’t use the plugin i have it active but i place the
and i can see the { code} and nothing higlighted
what am i doing wrong?
Hey,
You need to remove the = between code and type. So it becomes {code type=php}.
Pingback: 10 Un-Usual Wordpress Plugins that Improved my Blog » DivitoDesign
Another satisfied customer! Works great.
plug-in isn’t working for me – I’m running wp 2.6.2
I inserted the code
but it just displays as plain text. This is within an actual blog post. Is this plugin only for pages? thanks
It should work both in pages and posts,
be sure to use the right syntax as described aboveand download the latest version. If that still doesn’t work, please send me an email with your server details, so I am able to find the problem.Very Good~!!
Too bad it didn’t help you 🙁
I hope to get version 1.1 ready within three weeks.
Thank you Frank! 🙂
I tried exactly what you said. I now get the following error:
“Warning: cannot yet handle MBCS in html_entity_decode()! in /home/itrating/public_html/wp-content/plugins/fv-code-highlighter/phpHighlighter.php on line 19”
Since you mentioned that this will get fixed in the next version I am happy to wait until that comes out instead of pestering you with this, though.
Thank you for the great plugin! 🙂
tmax, thanks!
I guess you’re running PHP 4, since this function only works on 5.1 and up. However, the problem can be fixed!
Open the file phpHighlighter.php with notepad or your favorite text editor (it’s in the fv-code-highlighter directory), and search for the next line:
It should be line number 19.
Now replace that line with this line:
And everything should work perfect! 🙂
In the next release this problem will be automatically fixed, since it will get a better PHP highlighter.
Thank you for a great plugin Frank! 🙂
I got an error I wanted to run by you in case it is a bug. Of course it might just be my fault instead.
When I use the
on a code segment it all works well.
When I use the
on a code segment I get the error while the blog post is rendering:
Fatal error: Call to undefined function: htmlspecialchars_decode() in /home/itrating/public_html/wp-content/plugins/fv-code-highlighter/phpHighlighter.php on line 19
My WordPress engine is version 2.6.1
Thanks
Hey bighead,
Thanks for the compliment!
At this moment I don’t know much about Java, but I will try to get it implemented in the next release.
Hi, ur plugin is very nice, i am using it…but this version still not support JAVA. Anyway, i have modify it so that it able to format some simple JAVA code. I am wating for ur next release, hope that coming release ll include JAVA formating.Thanks ya, nice job!
Thanks, and thanks again for all your help and support!!
Awesome plugin my friend! Use it all the time.