A WordPress plugin for syntax highlighting

View demo page


  • Syntax highlighting for 240 languages.
  • Lightweight and super-simple usage.
  • Mobile-friendly: saves bandwidth and battery (no client-side code execution required, usually only one additional HTTP request). This is much better than using one of these heavy-scripted client-side solutions!
  • High performance, with near-zero additional load on the back-end. And in combination with a caching solution, this does not affect your page load time at all.
  • Line numbering (only if you want to). Code-number displacements never occur. Numbers are not copied in most browsers.
  • I have tested the default style with more than 20 themes, including Twenty Ten to Fifteen!
  • If you do not like the default style: just provide your on CSS file. Styles are highly & easily configurable.
  • Per-block styles: each code block on a single web page can be designed on its own.
  • Clean, small and valid HTML output. That’s super-important!
  • Clean and well-documented source code, using modern WordPress API calls.
  • Well-maintained since more than five years, and I’ll continue to provide support.
  • This is based on GeSHi, a reliable and well-established PHP highlighting engine, used by popular forum softwares such as phpBB or wiki applications such as Dokuwiki or MediaWiki.
  • Stability, performance and security are inherited from GeSHi. And I’ll continue to merge in upstream changes.


jgehrcke@googlemail.com or please leave a comment below.

What do you want to do now?


Here, I’ll just provide three quick examples. For more examples, please visit the demo page.
What follows is a snippet of source code, displayed by WP-GeSHi-Highlight with its default style sheet.

  1. function wp_geshi_filter_and_replace_code_snippets() {
  2.     global $wp_query;
  3.     // Iterate over all posts in this query.
  4.     foreach ($wp_query->posts as $post) {
  5.         // Extract code snippets from the content. Replace them.
  6.         $post->post_content = wp_geshi_filter_replace_code($post->post_content);
  7.         if (is_single()) {
  8.             $comments_array = get_approved_comments($post->ID);
  9.             // Iterate over all approved comments belonging to this post.
  10.             // Filter them, too.
  11.             foreach ($comments_array as $comment) {
  12.                 $comment->comment_content = wp_geshi_filter_replace_code(
  13.                     $comment->comment_content);
  14.                 }
  15.             }
  16.         }
  17.     }

The corresponding pre block is configured with the arguments lang="php" and line="1". The exterior block style (the borders, the shadows, etc.) is defined in the wp-geshi-highlight.css file.

Let us have a look at a different example. This time, the code block is configured with lang="bash" and we use a different block style, via the cssfile="another_style" argument:

$ dd if=/dev/zero of=image.ext3 bs=1M count=10000 oflag=append conv=notrunc

In this example, the WP-GeSHi-Highlight looks for another_style.css on the server and finds it. What follows is the content of another_style.css, using pure GeSHi styling, activated via lang="css" and cssfile="none" options:

.another_style {
  font-size: 12px;
  line-height: 13px;
  background-color: #EFEFF7;
  border-top: 1px solid silver;
  border-bottom: 1px solid silver;
  padding-left: 5px;

What you see above is the default pre-style of my WordPress theme combined with the styling as produced by GeSHi.

Usage reference

Write your post or page in the raw HTML editor. The general syntax for highlighting your code using this plugin is

<pre arguments>
[... CODE ...]

The required argument is:

  • lang="languagestring": allowed values are listed here.

Optional arguments are:

  • line="1": enables line numbering. Select the start number? See FAQ.
  • cssfile="string": selects a CSS file to style this code block.
    Allowed values:

    • "none": all block styling is omitted. The code is still highlighted by GeSHi.
    • "filename": If the file filename.css exists in the plugin directory or in WordPress’ stylesheet_directory (takes precedence), it is used to style the code block. Hence, if you store another_style.css on your server, you can use it by setting cssfile="another_style".

    If you do not set this at all, wp-geshi-highlight.css styles your code block.

  • escaped="true": the code is run through PHP’s htmlspecialchars_decode().

For examples of how these options work, make sure to have a look at the demo page!

How to apply your own styles

Permanently change the default style:
By default, wp-geshi-highlight.css from the plugin directory is inserted into the HTML head and defines the default code block style (in combination with your theme’s CSS code). You can permanently change the default code block style by placing your own wp-geshi-highlight.css in WordPress’ stylesheet_directory, which is your (child) theme’s style directory. If WP-GeSHi-Highlight finds it there, it takes precedence and is inserted into the HTML head instead of the default file. Such a custom style file survives WP-GeSHi-Highlight updates!

Apply different styles to certain code blocks:
Provide your own CSS file and use the cssfile option. Consider, for example, cssfile="another_style". This will make two things happen:

  • WP-GeSHi-Highlight puts the following structure around the HTML code generated by GeSHi:

    <div class="another_style-wrap5">
        <div class="another_style-wrap4">
            <div class="another_style-wrap3">
                <div class="another_style-wrap2">
                    <div class="another_style-wrap">
                        <div class="another_style">
                            HTML code generated by GeSHi

    As you can see, the names of the six CSS classes depend on the value given to cssfile.

  • WP-GeSHi-Highlight looks for another_style.css in WP-GeSHi-Highlight’s plugin directory as well as in WordPress’ stylesheet_directory. If it is found, it is included in the HTML header of your website (whereas the style sheet directory takes precedence over the plugin directory).

Hence, you have plenty of room to style your code block within another_style.css, using the six different CSS classes.


Can I change the starting line number?
Yes, try e.g. line="13". But this breaks XHTML strict compliance.

How can I use the pre and other HTML tags in my code?
Make use of HTML escape sequences and the escaped option. Write the code like that:

&lt;pre lang="html4strict" escaped="true"&gt;

It will end up like:

<pre lang="html4strict" escaped="true">

Note that the only difference between both code blocks is that in the upper one I did not use escaped="true" in order to demonstrate what you actually have to type.

Leave a Reply

Your email address will not be published. Required fields are marked *

Human? Please fill this out: * Time limit is exhausted. Please reload CAPTCHA.

  1. […] switched to a modified version of WP-GeSHi-Highlight. That turns the above Markdown […]

  2. Amedee Van Gasse Avatar
    Amedee Van Gasse

    WordPress tells me that this plugin is likely abandoned because it hasn’t been tested with the last 3 versions of WP.

    What is required for testing? Do automated tests already exist? How can I help?

    1. Jan-Philip Gehrcke Avatar

      Amadee! Thank you for this lovely question. The plugin should still work. I didn’t release new versions in a while because there was no need. Therefore, the metadata of the last release indicates that it has only been tested up to …. well. That makes the plugin look worse than it is. To my knowledge, it just works!

      > What is required for testing

      What I typically did for verification testing was to render various demo pages using the WordPress version in question. When I found that everything looks correct I made a release and confidently updated the ‘tested up to…’ metadata aspect.

  3. Oppadu Avatar

    I migrate my coding syntax plugin from Crayon to WP-Geshi, and I love to use it.
    But, somehow, this plugin doesn’t work on my board-plugin.


    May I ask how I can active the WP-Geshi plugin in other page or post type?:)
    Thank yoU!

  4. Sirus Avatar

    Great plugin, I like the elegant style. Is it possible to force it to be always left aligned, because the code will show right-aligned in right-to-left languages such as arabic. I tried to force the style, but it didn’t work.

  5. […] COBOL „Hello, World!“ mit klassischer Druckausgabe. Ist auch ein guter Test für das WP-GeSHi-Highlight […]

  6. Patrick Lalemand Avatar
    Patrick Lalemand

    Hi, I’m using a language not listed in the “standard” geshi : WinDev (from PCSOFT). I’ve made a windev.php file and put it in wp-content/plugins/wp-geshi-highlight/geshi/geshi. It works fine. But every update of the plugin delete my file ! How can I do to avoid that ? Thanks!

  7. Mansimar Avatar

    Why does the scroll bar dissapear and the lines are wrapper when I use my own stylesheet or another_style?

  8. Thomas Maurer Avatar

    Great Work! Thank you for creating and keeping the plugin up to date. Does it work with PHP 7.3? or and higher?

    1. Jan-Philip Gehrcke Avatar

      Yes, it does! I currently run 7.4.33.

  9. Hadret Avatar

    Hello @jgehrcke:disqus! I just wanted to say: thank you so much for this wonderful plugin! I’ve been looking for good code highlighter and ended up with some mish-mash of two plugins, still not being happy how it looked and behaved. Yours did the trick straight-away, it looks gorgeous and it doesn’t auto-wrap lines. Thank you! 🙌🏻

  10. Dasagriva Manu Avatar

    Hello @j@jgehrcke:disqus – I was using code-prettify plugin which only needs the “pre” tag and no “lang=” attribute is required. Now I want to use your plugin but would I now need to modify all of my previous posts (>200) which just have a “pre” tag for code highlighting? Can it not work with “pre” tag only? I read your site but didn’t find a related reference. Please suggest, I really want to use WP-GeSHi-Highlight but don’t want to modify the old posts.

    1. Jan-Philip Gehrcke Avatar

      Interesting suggestion; I acknowledge this as a meaningful request. I however do hope that you can understand that crafting a solution for this implies the risk of breaking existing environments. Given the little time I can spend on maintaining this project, I think I must limit myself to bug fixes and similar maintenance tasks; adding features is at this point a brittle operation putting happy users at risk.

  11. Sven Sevke Avatar

    Hi! Are you planning to make the plugin ready for PHP 7.1?

    See example of a warning: https://blog.sevke.net/?s=auge

    Thanks, Sven

    1. Jan-Philip Gehrcke Avatar

      Hey, I have published a patch release today. It should make the warning disappear. Please try it out! Thanks for using the plugin.

      1. Sven Sevke Avatar

        Yes, it works. Thanks for the quick fix!

  12. LimeBush Avatar

    wp-geshi-highlight.php line 401

    $theme_dir_url = get_stylesheet_directory_uri() + "/";

    change to

    $theme_dir_url = get_stylesheet_directory_uri() . '/';
    1. Jan-Philip Gehrcke Avatar

      I will consider to do that. Do you mind elaborating on this, why does this matter in practice? :) I think it would be nice to have the reasoning explicitly stated here, for posterity. Thanks!

      1. John Avatar

        In php 7.2 it is a warning – “A non-numeric value encountered in /var/www/wordpress/html/wp-content/plugins/wp-geshi-highlight/wp-geshi-highlight.php on line 401”

        1. Jan-Philip Gehrcke Avatar

          Understood. I just published a patch release.

  13. Ruud Avatar

    How can I add automatic line breaks? Sometimes you have long line of code and now you get a horizontal scollbar. Automatic line breaking and preserving line number would be a great addition to the nice syntax highlighter.

  14. huisdierenverzekeringvergelijk Avatar

    How can I add automatic line breaks? Sometimes you have long line of code and now you get a horizontal scollbar. Automatic line breaking and preserving line number would be a great addition to the nice syntax highlighter.

  15. […] settled on WP-GeSHi-Highlight, which was active and up-to-date. It provides syntax highlighting and preserves your code […]

  16. Chrisyphus Avatar

    Can you add Julia syntax highlighting by default to your plugin? I showed how I made it work here:


    1. Jan-Philip Gehrcke Avatar

      I have just released WP-GeSHi-Highlight 1.3.1. It contains the latest and greatest of the GeSHi language definition files. That includes Julia support! :) Hope you like it.

  17. […] even though no plugins currently support it. The way I was able to get it to work was to use the WP-GeSHi-Highlight WordPress plugin which uses GeSHi to perform the syntax highlighting. Sure enough, an unofficial […]

  18. […] 需要了解更多用法和帮助,请访问作者官网 […]

  19. […] just installed the WP-GeSHi-Highlight plugin by Jan-Philip Gehrcke. I’ll be posting tutorials, walk-throughs, and code snippets as […]

  20. […] verwende das Plugin WP-GeSHi-Highlight für Code-Formatierungen von X++ und dies ist ein erster […]

  21. […] This is a test post for the plugin WP-GeSHi-Highlight: […]

  22. woodle Avatar

    Hello Jan-Philip. Very nice PlugIn and thank you sharing it with us.
    But switching between plaintext and visual Editor make some Problems. It converts the Special signs (like & to &), and your engine did not recode it.
    Is there a solution for that?

    1. Jan-Philip Gehrcke Avatar

      Hey, thanks for asking. As documented, this plugin should only be used with the raw editor. The reason is that there is no clean solution for both having code blocks marked with pre tags and have them work across editor switches.

    2. siva raj Avatar
      siva raj

      Jan-Philip,me to have same problem, is there any solution for this now

  23. Andrey Avatar

    Hello Jan-Philip, I will try to ask my question again. So.
    When I use your plugin so

    <pre><code>&lt;pre lang="sql"&gt;UPDATE `wp_users` SET `user_pass` = MD5('New_Password') WHERE `user_login` = 'Administrator'

    it’s all right.

    But for convenience I want use shortcode to insert code into visual editor WP.
    It’s my little shortcode:

    <pre><code>function shortcode_code_func ($atts, $content = null) {
            "lang"      =&amp;gt; 'php'
        ), $atts));
        return "&lt;pre lang='$lang'&gt;$content&lt;/pre&gt;";
    add_shortcode("code", "shortcode_code_func");

    But when I use it this don’t work.

    <pre><code>[code lang="sql"]UPDATE `wp_users` SET `user_pass` = MD5('New_Password') WHERE `user_login` = 'Administrator'[/code]

    Your plugin run before the shortcode text will be replaced and tag
    PRE not filtered your plugin.

    1. Jan-Philip Gehrcke Avatar

      Hey, this looks like being a side effect of this plugin running very early as well as very late in the filter processing chain. I understand that what you try to achieve could be great, but I am quite sure that this requires changing the filter priorities. This, on the other hand, might subtly break this plugin in various scenarios, when combined with certain other plugins. That is, this could break backwards compatibility. Since your use case is not documented by WP-GeSHi-Highlight, users must not expect this to work. A corresponding change would not be a bug fix, but a new feature, possibly breaking other things. Hence, it would require a major version change. So you can not expect this to happen soon. How bad do you need that? Do you have other options?

  24. Andrey Avatar

    Hello! Tnx for your plugin!

    I try wrap <pre> output into shortcode like this

    function shortcode_code_func ($atts, $content = null) {
            "lang"      => 'php'
        ), $atts));
        return "<pre lang='$lang'>$content</pre>";
    add_shortcode("code", "shortcode_code_func");

    and paste it in visual editor

    [code lang="sql"]UPDATE `wp_users` SET `user_pass` = MD5('New_Password') WHERE `user_login` = 'Administrator'[/code]

    But the problem is your plugin run before the shortcode text will be replaced and tag pre not filtered your plugin.

    Search right place in the text editor is very difficult when a lot of code. So I try use shortcodes.

    1. Jan-Philip Gehrcke Avatar

      Did you precisely follow the usage instructions? I only see [code lang="sql"], which indicates wrong usage. Other than that, your questions is really not understandable. Can you try again, with proper formatting?

  25. Vicente Avatar

    Gracias por tu buen trabajo.
    Me ha servido mucho.


    1. Jan-Philip Gehrcke Avatar

      Thanks for your feedback, seriously!

  26. jobst Avatar

    I have got this in my code, I have edited it using TinyMCE advanced in TEXT mode:

    <pre line="1" lang="html4strict" >
    define('AUTOSAVE_INTERVAL', 300 );
    define('WP_POST_REVISIONS', false );

    It does not display the line numbers.

    What am I doing wrong?


    1. Jan-Philip Gehrcke Avatar

      What does it display instead?

  27. […] Currently, 240 languages are supported. Documentation, FAQ, and comments can be found at gehrcke.de/wp-geshi-highlight. […]

  28. […] found a good plugin for GeHSI style code formatting which I was using in Serendipity, albeit the syntax is very slightly different so I have some work […]

  29. […] For more information about WP-GeSHi-Highlight, you might want to visit http://gehrcke.de/wp-geshi-highlight. […]

  30. Mike Doherty Avatar
    Mike Doherty

    My blog periodically goes down, with nginx giving a 500, and the php5-fpm logs showing that index.php has taken too long to execute. With more verbose logging, it seems like the geshi plugin is involved:

    ==> /var/log/php5-fpm/php5-fpm.log  /var/log/php5-fpm/www.slow.log <==
    [08-Jan-2014 23:10:06]  [pool www] pid 4863
    script_filename = /var/www/hashbang.ca/index.php
    [0x0a8dd854] array_splice() /var/www/hashbang.ca/wp-content/plugins/wp-geshi-highlight/geshi/geshi.php:4676
    [0x0a8dd3a8] optimize_regexp_list() /var/www/hashbang.ca/wp-content/plugins/wp-geshi-highlight/geshi/geshi.php:1666
    [0x0a8dc1f4] optimize_keyword_group() /var/www/hashbang.ca/wp-content/plugins/wp-geshi-highlight/geshi/geshi.php:2042
    [0x0a8d6568] build_parse_cache() /var/www/hashbang.ca/wp-content/plugins/wp-geshi-highlight/geshi/geshi.php:2181
    [0x0a8d5d8c] parse_code() /var/www/hashbang.ca/wp-content/plugins/wp-geshi-highlight/wp-geshi-highlight.php:338
    [0x0a8d5b34] wp_geshi_highlight_and_generate_css() /var/www/hashbang.ca/wp-content/plugins/wp-geshi-highlight/wp-geshi-highlight.php:147
    [0xbf9bee28] wp_geshi_main() unknown:0
    [0x0a8d54f8] call_user_func_array() /var/www/hashbang.ca/wp-includes/plugin.php:429
    [0x0a8d4d98] do_action() /var/www/hashbang.ca/wp-includes/template-loader.php:12
    [0x0a8d4c58] +++ dump failed

    Have you ever seen this error before? Do you have any ideas for resolving this? At present, I simply restart php5-fpm, which brings the blog back up until the next time.

    1. Jan-Philip Gehrcke Avatar

      Hello, and please excuse the late reply. I have never seen this before, and am using a similar config (nginx, php5-fpm) myself. Since GeSHi is quite popular itself, it would surprise me if this wouldn’t already be discussed, if this really is a GeSHi issue. So, I would recommend heading over to the GeSHi mailing list or issue tracker and see what you can find there. If you don’t find anything, then this problem is most likely related to your individual system.

    2. Malick Jawed Xafar Avatar
      Malick Jawed Xafar

      can anybody share me the media where x++ coding works

  31. glerner Avatar

    I haven’t tried it yet, and the WordPress per-post disable-visual-editor-wysiwyg plugin looks like it might be helpful. Gives you a check box to disable the visual editor for individual posts, no having to remember not to click the visual editor. Or maybe the WP-Geshi-highlight could detect that plugin and set that check box if there is a pre lang=”…” tag, who knows…

  32. glerner Avatar

    The wp-geshi-highlight.css file isn’t being read in my system from /public_html/wp-content/plugins/wp-geshi-highlight
    but works fine in /public_html/wp-content/themes/twentythirteen
    (not twentythirteen/css )

    I suggest these changes, TwentyThirteen leaves a Lot of space between pre lines:

    div.wp-geshi-highlight li.li1 pre {
    /* override TwentyThirteen styling */
    margin-top:0; margin-bottom:0;
    padding:0 5px;
    .wp-geshi-highlight {
        font-family:Consolas,'Lucida Console','DejaVu Sans Mono',monospace;

    Web CSS Font Family List, updated for what is installed on most Windows/Mac/Linux machines, from
    suggests these series of fonts either of which should be great for code:

    font-family:Consolas,'Lucida Console','DejaVu Sans Mono',monospace;
    font-family:'Courier New',Courier,'Nimbus Mono L',monospace;
  33. […] By default, the wp-geshi-highlight.css in the plugin directory is inserted in the HTML head. You can permanently change the default code block style by placing your own wp-geshi-highlight.css in WordPress’ stylesheet_directory (which usually is the theme style directory). If WP-GeSHi-Highlight finds it there, it takes precedence and is inserted into the HTML head instead of the default file. Obviously, such custom styling survives WP-GeSHi-Highlight updates. (from the docu) […]

  34. Mike Doherty Avatar
    Mike Doherty

    Is it possible to add support for inline code? Sometimes, you want to highlight just a few characters and not break out of the paragraph.

    1. Jan-Philip Gehrcke Avatar

      Hello Mike,

      thanks for your questions.

      ad 1) “Inline code highlight” is possible, in general, yes — but not with the current version of WP-GeSHi-Highlight, I am sorry. I agree that it would be very convenient and seriously considered implementing it for a while already. I don’t however want to make wrong promises regarding the time frame. So, if you need it right now, please have a look at other solutions.

      ad 2) The language-specific CSS code is generated dynamically. Of course it would be possible to manage corresponding files in a cache-like fashion and to dynamically link to these files from the main HTML document. However, I do not see the advantages outweighing the associated overhead. Do you? :)

      HTH, Jan-Philip

  35. Tai Avatar

    Plugin works brilliant, but I just noticed that when the post is on the front page it’s not getting converted, but when I click into the post to read the full post I see the syntax highlighting ?

    Is this normal is there a way for me to have it work on the front page as well ?

    1. Jan-Philip Gehrcke Avatar

      Tai, please excuse the late answer. Is this still an issue for you?

      1. worldfinestmodels Avatar

        why can’t you have the default have the coloring and the numbers? was that really difficult? happens default is this white space and no number….also with the example you giving you never gave how it should be written exactly in worpress like ….i mean that is not cool at all

        1. Jan-Philip Gehrcke Avatar

          I have difficulties understanding your question. Please have a look at http://gehrcke.de/wp-geshi-highlight/#usage and try to reformulate your problem.

  36. Du Avatar

    Hi JP,
    I also would like to use your plugin, but I’m unable to get it running! :S Would you mind taking a look?

    1. Jan-Philip Gehrcke Avatar

      You have to be very precise about which steps you have performed and what exactly happened. Otherwise, it is not easy to help.

  37. […] including WP-GeSHi-highlight and Better WordPress Syntax Highlighter. From few tested I found that WP-GeSHi-Highlight has the best performance but still – it wasn’t so great. I was thinking – is […]

  38. […] zu der Engine gibt es hier. Ansonsten kann man sich, bei Interesse noch ein wenig auf der Plugin-Homepage […]

  39. Narga Avatar

    Can you change the another css style by searching it in theme folder like wp-syntax. The theme developer will be include it in their theme instead upload it to plugin folder.
    Please include all css code in another_style.css, in this version the css code display with html code.

    1. Jan-Philip Gehrcke Avatar

      Please have a look at the current development version. The 1.0.8 release will prioritize CSS files found in the theme directory over those that are in the plugin directory.

    2. Jan-Philip Gehrcke Avatar

      “Can you change the another css style by searching it in theme folder like wp-syntax” — this has been implemented for a long time, sorry for the late response.

  40. FreemanRU Avatar

    From description: “Line numbers are not copied”
    But it doesn’t work for IE9.

    1. Jan-Philip Gehrcke Avatar

      You are right.

      More than a year ago, I tested this with IE8. Now, we have to accept that IE9 copies the numbers from numbered lists. Unfortunately, this behavior is out of our control.

  41. chitgoks Avatar

    do you have plans to add a collapse feature for the code?

    1. Jan-Philip Gehrcke Avatar

      I don’t have those plans.

  42. […] gotowych dodatków takich jak Better WordPress Syntax, czy WP-GeSHi-Highlight postanowiłem zrezygnować z tych udogodnień i wykorzystać naprawdę ciekawe i na dłużą metę […]

  43. Bharat Mandava Avatar

    Fantastic plugin, its loading fast and displays code without any clutters.

  44. Markus Ewald Avatar

    Ah, I didn’t see the escaped="true" option. That does exactly what I want!

    1. Jan-Philip Gehrcke Avatar

      Thanks for your feedback!

  45. Markus Ewald Avatar

    This plugin looks really good and from what I see in these comments, your support is just fantastic :)

    I tried it on my blog and while it does work fine overall, it seems to escape HTML entities a second time (for example; &lt; becomes &amp;lt;). Personally, I like to put code with HTML entities into my <pre />-tags so the post stays valid HTML even without a syntax highlighter installed (otherwise, everything inside the <pre />-tags would be fair game and you couldn’t post an actual </ pre> without accidentally ending the code snippet /and/ producing invalid HTML).

    1. Jan-Philip Gehrcke Avatar


      thanks for your inquiry. However, I am not sure if I properly understood the problem you’ve observed. Currently, I think that what you would like to accomplish (putting HTML entities in the pre block) is possible. Please look at these comments:



      If this does not help, I was too dumb to understand your problem :). In this case, please describe it again…


  46. Brad Avatar

    JP, simple yet effective plugin. Thanks. I just wanted to find out if anyone is having the problem with losing the pre arguments once switching view from HTML to VISUAL in the post. What I am saying is for example, i have <pre lang="php" escaped="true"> in the HTML view, once i switch to VISUAL and then back to HTML view, the syntax would go back to <pre lang="php">. This is a problem when i have > and < all over the place. Any idea?


    1. Jan-Philip Gehrcke Avatar

      Switching between the raw HTML editor and the visual editor is expected to cause problems. Please just don’t do it.

  47. Carina Zona Avatar
    Carina Zona

    The plugin’s css file, wp-geshi-highlight.css, does not seem to be registered with theme editor. I’ve tried activating various different themes to see if it’s a theme itself that’s at issue. But wp-geshi-highlight.css is never displayed in theme editor’s file list.

    1. Jan-Philip Gehrcke Avatar


      sorry for the late reply. I’ve not “registered wp-geshi-highlight.css with the theme editor”, because I did not know that this is possible. Maybe I will look into that. Are you still requesting it? :)

  48. Jez Avatar

    I have to say I think this code editors very good, first one I’ve used but I have to say it’s very good indeed.

    Very well done also with regards to anyone not wanting to do HTML instead preferring to use the Visual Editor (WYSIWYG), why do coding? That’s my opinion anyways, I mean when I was at University I took about a week of just constant HTML editing to get myself used to the markup, one of my hates is when people call HTML and indeed CSS coding when it’s not coding at all it’s just presentation and markup, the only logic than can be used is when you want to use hacks to override settings if browser can’t display what you want.

    I mean I never use anything like Dreamweaver or anything like that prefer to keep my HTML knowledgeable to myself where ever possible, just a personal feeling though, one of the apps I use for syntax highlighting is Notepad++ used to use Notepad2 but don’t like using that anymore.

    But I am no visual designer I am a web developer so I stick to coding myself, doing a TCP network series of tutorials in integrating Flash as a multiplayer game format for TCP networks, so this code highlighters really good to illustrate what I want.

  49. Glen Avatar

    When CSharp code is rendered, the tab spacing is 8 instead of 4. Any ideas?

    1. Jan-Philip Gehrcke Avatar

      Since WP-GeSHi-Highlight is using the pre-method, tabstops are rendered by your browser — there is nothing GeSHi can do for you.

      But there is something else…: maybe you know that there is a philosophical war between people fighting for tab indents in code (\t characters) vs. people saying that spaces are the one and only. I am one of the latter ones. So, if you like being able to define the “optical characteristics” of your code for every single displaying device or editor, then just use space-based indentation. Then, no ambiguity is left.


  50. Linux Rawkstar Avatar

    Where’s the “donate” button? Let me show my thanks by providing you with a small token of my gratitude.

    1. Jan-Philip Gehrcke Avatar

      Awesome. It’s funny.. for submitting a plugin to wordpress.com, one has to (or at least should) define a “donate” link. During that time, I’ve hidden my PayPal donate link here:


      Thank you!

  51. Dan Avatar

    Any chance you update the plugin to support markdown for editing text entries?

    1. Jan-Philip Gehrcke Avatar


      I think a syntax highlighting plugin should not necessarily support something like markdown or restructured text. However, you are right and there should definitely be some plugin out there implementing these kinds of things.

      I would suggest searching the web for “wordpress + restructured text” or “wordpress + markdown” and then looking into something like this.


  52. Gregor Avatar

    Hey, danke für das Plugin. Funktionert auf Anhieb besser als das alte WP-Syntax. Eine Frage: mit GeSHi kann man ja auch relativ simpel einzelne Zeilen hervorheben. Super-praktisch in Tutorials u.ä. Soweit ich sehe, hast du das noch nicht in dein Plugin übernommen.

    <pre lang="JavaScript" line="1" hightlight="2,4,8-9">

    Wäre super wenn du das noch einbauen könntest. :)


    1. Jan-Philip Gehrcke Avatar

      Hey Gregor,

      I’m answering in English, so that everyone is able to follow :) Also, I’ve merged your two comments and I hope you are fine with that.

      Enabling highlighting is a very good suggestion! I will look into that as far as I find the motivation and time. It’s just that there is a lot of stuff at the moment with higher priority than working on this plugin (e.g. my PhD project).

      It will happen… and don’t hesitate bothering me again if it is really important for you :-)


  53. tiaurus Avatar

    Unfortunately, this plugin also does not allow subscribers to comment embed code – it is cut. For example, the subscriber inserts the code: http://codex.wordpress.org/Function_Reference/get_currentuserinfo
    and obtained:

    user_login . "\n";
          echo 'User email: ' . $current_user->user_email . "\n";
          echo 'User first name: ' . $current_user->user_firstname . "\n";
          echo 'User last name: ' . $current_user->user_lastname . "\n";
          echo 'User display name: ' . $current_user->display_name . "\n";
          echo 'User ID: ' . $current_user->ID . "\n";
    1. Jan-Philip Gehrcke Avatar


      Sorry for the late reply. In fact, only non-registered users experience this problem and it seems it is either a filter by Akismet or WordPress. Anyway, it can be solved by
      1) using the HTML escape sequences < and > in the code block
      2) using the option escaped=true

      Do it like that:

      <pre lang="php" escaped="true">
          [your php code including HTML escape sequences, see below]

      With the PHP code looking like:

      <?php global $current_user;

      The result is:

      <?php global $current_user;

      escaped="true" translates HTML escape sequences back to their special characters. So, if you experience problems like that it is not specific to this plugin. “Bad” character combinations, that could inject malicious code to the website, are filtered out… in all these cases it is a very good idea for you/your users to enter the HTML escape sequences > and < directly into the pre block.

  54. raumin Avatar

    god ! Cant post these characters :s

    < and >


    1. Jan-Philip Gehrcke Avatar

      Akismet/WordPress seem to apply quite strict filters on comment “code” provided by non-registered users. I recommend to use HTML escape sequences and the option escaped=true.
      Use the following code:



      <pre lang="text" escaped="true">



      It works :)

  55. Laszló Tatai Avatar

    Now here :

    Here my code :

    pre  lang="html4strict" line="1"
    pre  lang="cpp" line="5"
    pre  lang="html4strict" line="1"
    1. Jan-Philip Gehrcke Avatar

      Please use HTML escape sequences in your original code block and the option escaped="true" in your pre tag.

  56. Dennis Avatar

    Hi Jan-Philip,

    vielen Dank für dieses Plugin. Eine echte Alternative. Sobald ich genug Erfahrungen gesammelt habe, gibts einen Review ;)

    1. Jan-Philip Gehrcke Avatar

      Danke für die Blumen :-)

  57. Doug Weathers Avatar

    Thanks for the quick reply!

    I did some more looking around and found that the SyntaxHighlighter plugin (used on the WordPress.com site) looks more like what I want to see.

    It’s less efficient and uses Javascript, but for now it’s the best-looking solution. I’ll revisit this issue if it becomes a problem.

    You can see how SyntaxHighlighter looks on my blog at http://www.gdunge.com/2011/03/22/playing-with-pi.

  58. Doug Weathers Avatar


    Thanks for the great plugin!

    I have a question.

    I don’t like how the default line numbering feature looks. Is there a way to get more of the GeSHi line numbering options, like the “fancy” version?

    For an example of what it looks like on my site, see


    Thanks again!

    – Doug

    1. Jan-Philip Gehrcke Avatar

      Hey Doug,

      1) Regarding the line spacing, your WordPress theme screws up the default PRE style. See what it looks like on this page here:

      Your theme sets a huge lineheight and a huge margin-bottom. Get yourself a plugin for live-editing styles in your browser (like Firebug for Firefox) and change the responsible parts in your style.css. In your case, it’s around lines 470-480..:

      #content pre, #content kbd, #content tt, #content var {
          font-size: 15px;
          line-height: 21px;
      style.css (Zeile 484)
      #content p, #content ul, #content ol, #content dd, #content pre, #content hr {
          margin-bottom: 24px;

      A few comments above, another guy had similar problems and solved them as proposed: http://gehrcke.de/wp-geshi-highlight/comment-page-1/#comment-5376
      If you get your styling properly, your blog post about the “bad look” remains abundant :-) On a side note, there is no way to remove the dots, because I told GeSHi to use an ordered list to create line numbers. And browsers typically use numbers and dots for ordered lists.

      2) What do you mean by “more of line numbering options”? There is only “fancy” or is there more? In case of “fancy”, if you insist, I could introduce a new argument within the next version to enable “fancy” look… but I find that this is a needless feature :-) Convince me why people need it :)

      Thanks for your question and suggestion and I’m happy to read your answer ;)

  59. RunTimeWorld Avatar

    Your plugin rocks! Just opened my blog and tested it, thanks a lot and keep up the good work!

  60. Roshan Avatar

    I like the idea of having a post level tag. A couple of reasons for this:

    1) Usually this sort of per-post configuration is small.

    For larger configurations, its perfectly ok to ask people to go create a custom format php (like you had originally asked me to do with bash.php.) There is no advantage to you duplicating that functionality and having to maintain all that code.

    For an example of a small configuration take a look at my post about this tool called hg-gateway. The only keywords I needed to add were “hg-gateway” along with its subcommands.

    2) More importantly the custom configuration of a post will be saved and tracked along with the post itself rather than be stored on random locations on the server.

    A few more thoughts:

    1) The syntax for the per post extension could be done in a more
    HTML friendly manner. For example, enclose the ini format in HTML comments so that someday if your plugin stops working, the post is still readable and the ini formatting stays hidden.

    2) You could still add extensions to the pre tag. I agree with your concern that this quickly gets ugly for large confirgurations, but for small ones, it should be simple. You can use the same naming conventions as your ini format. For example you could have the tags “add_keyword.word=” and “add_keyword.word=”. Btw wouldn’t it be better have:


  61. Igor D. Avatar

    Is there any way we can remove another_style-wrap 2,3,4,5 without changing plugin source? I did that to simplify style and created JQuery script to “show source”. You can see it on my website.

    1. Jan-Philip Gehrcke Avatar


      the cssfile=none option removes too much, yes? You want to keep



      Currently, you can only do this within the source, as you did. Do you think I should introduce a parameter to change this behavior? In which way would you prefer to define this? Would this be something other users need, too?

      Thanks for your input,


      1. Igor D. Avatar

        For myself I wanted to simplify things so it is easier to make “show source” with pure JQuery/HTML (no PHP solution). For others I am not sure. I can achieve all stylings with just one wrapper and for the shadows I need just one DIV. I don’t mind changing source – guess other users should also vote on this :)

  62. Peter jung Avatar
    Peter jung

    Wondering what to do when the code itself contains
    open and closing PRE tags. What do you recommend?

    1. Jan-Philip Gehrcke Avatar


      this question drove me nuts for one day, where I wanted to find an easy way to get around this problem. There of course must be an intelligent solution. I did not investigate this deeply and, hence, did not find it yet. But this would mean a big rewrite, for sure — or I don’t see the obvious ;-)

      So, at the moment, you definitely must not use closing pre-tags within a code block at all. I’m sorry.

      Hopefully, I’ll come up with a more intelligent parser one day.

      1. Igor D. Avatar

        Please do not remove PRE tags if you want to be compliant with HTML specification. You can use CODE tags inside PRE (not the other way around). I just tested this with GeSHi and WP-GeSHi-Highlight and it’s working perfetly :)

        1. Jan-Philip Gehrcke Avatar

          Thanks for your opinion, Igor. Things are not perfect. I understand people trying to present code including PRE tags. And the only dirty solution there is so far, is not to use closing pre tags in the standard way. At the moment, you could e.g. insert a space between slash and pre:

    2. Jan-Philip Gehrcke Avatar

      The obvious solution is so obvious… :D

      In your “code source” please use HTML escape sequences. At the same time, use the escaped="true" option in the corresponding pre tag. To demonstrate this, I’ll show you the same code block two times. Once without escaped="true" and once with.


      <pre lang="text">


      <pre lang="text">
  63. Roshan Avatar

    Hi Jan-Philip,

    Thanks for your reply. I was able to create a custom bash.php as you suggested and this does solve my problem.

    However like you say, it would be better to configure this in the body of the post. I am afraid I will quickly accumulate a large number of these custom files and that I will lose settings like this every time I make changes to the blog, reinstall the plugin etc. I have to take care to remember and back these up.

    It would indeed be good if you could do this inline, or support some sort of post-level tag where these can be configured, such that they don’t have to be repeated for each code snippet within that post.

    Thanks again,

    ps. Do consider enabling “Comment Reply Notification” for your blog here. That way I would have known as soon as you had replied.

    1. Jan-Philip Gehrcke Avatar

      Hey Roshan,

      it’s good to have such suggestions. I definitely consider to implement what you propose. However, it will need time, because at the moment there are several entirely different things for me to do — with higher priority.

      I just installed the comment reply notification plugin, so hopefully you’ll get an email now :-)


      1. Roshan Avatar

        I did get your reply email. Thanks :)

        1. Jan-Philip Gehrcke Avatar


          strict implementation of the add_keyword, remove_keyword, add_keyword_group, and remove_keyword_group methods allows the user to provide tons of parameters (indices, words, colors, …). I do not like doing this inline within the PRE tag, because there data cannot be structured properly. I think using some ini-file format would be a more appropriate solution. Hence, I’m thinking of something like this:

          key = 1
          word = rofl
          key = 5
          word = ugaga
          key = 1
          styles = ...
          case_sensitive = ...
          word1 = 
          word2 =

          Such an “ini-string” is easy to create for the user and easy to parse from PHP. But how to provide this ini-string? I see two ways:

          1) Introducing a new “keywordcfgfile” argument to the PRE tag. There, you could point to an ini-file on your server, which then is read and parsed.
          2) Introducing a post-level start and end marker (like “–KEYWORD_DEF_START–” and “–KEYWORD_DEF_END–“), so that this ini-string could be provided at the beginning of the post.

          What do you think?


  64. Roshan Avatar

    Hi Jan,

    I just started using your plugin. Is there some way that I can add keywords to code under a particular “pre” tag so that they get highlighted correctly? Lets say I am writing a blog entry about a particular shell command and “pre lang=”bash”” does not highlight this command name by default, is there someway that I can ask it to?

    Similarly, can I remove keywords?

    Thanks in advance,

    (Sorry about the last comment being completely unreadable – should have known better than to put actual “pre” tags in there)

    1. Jan-Philip Gehrcke Avatar

      Hello Roshan :)

      GeSHi, the backend highlighting engine I am using in the plugin, allows for adding/removing keywords. Good news so far. Now, I see two possible ways to accomplish what you want.

      1) Dirty, but maybe fastest way for you for now: Look at http://qbnz.com/highlighter/geshi-doc.html#language-files to see how to define a language file. On your server, go to your plugins/wp-geshi-highlight/geshi/geshi directory. Regarding bash, you could copy bash.php to bash_custom.php and add your own keywords there. This is not exactly what you asked for, because it would work ‘semi-globally’, wherever you then use pre lang="bash_custom"… but it works :)

      2) I definitely see some way to realize exactly what you asked for: enable more arguments for the pre tag and forward them to the GeSHi API to add/remove keywords to specific keyword groups on the single code-block level. I could even think of let the user define new keyword groups. But this has to be done very carefully and definitely requires some time to accomplish and test. I don’t know if I can do this at the moment…

      So please, tell me if you’re lucky with solution (1). If not, I will have to see what I can do :)


    2. leonnib4 Avatar

      If you’re looking for simplicity try:


  65. Alejandro Palacios Avatar

    Thanks a lot for sharing this beautiful plugin Jan.

    2 questions:

    1) Within WordPress, can i change the height of the frame where the code is displayed ?
    2) Is there a download for non-Wordpress users who want to use it in their websites ?

    thanks again !

    1. Jan-Philip Gehrcke Avatar

      Hello Alejandro and Tim,

      thanks for using the plugin :-)

      The short answer for both of your questions is: 1) no and yes 2) no.

      The long answers:

      ad 1)
      The height of the ‘code box’ is chosen dynamically by the browser based on the height of the content and some static padding (top and bottom), which is defined via CSS code. You can change this CSS code either within the default CSS file wp-geshi-highlight.css or within the CSS file you are using. The padding you set there then is applied to all your code blocks.

      Do you think that being able to set this (top/bottom)-padding in a per-block-fashion via e.g. pre lang="x" padding="17px" is desired? Would definitely make some work to implement and, currently, I don’t see the huge benefit :)

      ad 2)
      This is a much too general question. As this is a WordPress plugin, the code of this plugin is adjusted to WordPress. So you cannot ‘simply’ apply this plugin to ‘other websites’. But, of course, there are ways to achieve syntax highlighting in the same fashion as this plugin does, even on non WordPress-based websites. Just tell me more about your case.

  66. Nick Avatar

    Ah, okay. Yeah, I kinda figured that it wasn’t your plugin, but yours is the first syntax highlighter I’ve used so I wasn’t sure. Thanks for the response!

    And thanks for that link. But for some things, the visual editor is just easier. :)

  67. Nick Avatar

    Love this plugin. But I notice that if I add xml to a post (inside a ‘pre’ block) then switch to the visual editor, the xml I just wrote gets severely truncated. I don’t know if the wordpress visual editor just doesn’t “like” xml code or if this has something to do with your plugin, but I was curious to get your input on the matter. Thanks!

    1. Jan-Philip Gehrcke Avatar

      Hey Nick,

      hope you don’t mind that I modified your comment here :-)

      This is likely because the visual editor is simply not suitable for writing content on the “code level”. It creates HTML code itself in the output, so it doesn’t like HTML-like code (e.g. XML) in the input.

      I think that the issue you’re experiencing will happen even without my plugin.

      Maybe I didn’t state this clearly enough, but for using WP-GeSHi-Highlight and other plugins like this (that require writing code with < > letters), you should never use the visual editor.

      Within my WordPress installation, I even disabled the visual editor at all :-) To do this, see e.g. http://www.themelab.com/2008/05/17/how-to-get-rid-of-the-wordpress-visual-editor/

      Take this chance to learn some HTML! You will not regret.

  68. Jesse Bye Avatar

    Thanks for your reply! I disabled all the other plugins I was using (Akismet, Lightbox Gallery, and WordPress.com stats), but no change, the plugin still doesn’t show up. As you’ve probably noticed, I’m using a very slightly modified version of Twenty Ten. However, I did try another theme and still the same problem. Everything else is pretty much standard, just a vanilla WP installation with no modifications.

    If it would help you diagnose things, I could setup an admin account for you so you could login and look at things for yourself. Just let me know if that’s something you would like to do.

    Thanks again for your help.

    1. Jan-Philip Gehrcke Avatar


      as I have to get down to this problem, I really appreciate your offer. I hope this helps. Not everybody would do this :)

      Would you mind to send me an email to jgehrcke@googlemail.com with further instructions? I think I won’t manage to look into this before the end of the week, but better late than never.

      Thank you so much,


    2. Jan-Philip Gehrcke Avatar

      I just looked through your HTML output again and saw this:

      If you have really typed it like this, then the solution is very easy :) Get rid of the needless code tag and use the plugin like

      instead (without the additional space I included here). Let me know if this does it :)

      1. Jesse Bye Avatar

        Aha! That was the problem! I didn’t read your instructions closely enough to see that you said “pre” instead of “code”. Once I wrapped the code in just a pre tag, it worked exactly as expected. Thank you so much for your assistance!

        One thing I noticed now that its working is a little glitch in the styling of line numbers — the numbers are cut off (on the left), and all the lines have too much space between them (see the example page again). Any ideas?

        1. Jan-Philip Gehrcke Avatar

          Good, then issue 1 is solved :)

          Regarding the “optical” problems, there is some conflict between the CSS of your theme and the standard CSS of WP-GeSHi-Highlight. Your theme styles pre and ol generally, which overrides the styles of the plugin. I am not sure what I can do to avoid such things in the future. But for now, you definitely can adjust these two points:

          In the style.css of your WordPress theme, change around line 486 to

          #content p, #content ul, #content ol, #content dd, #content pre, #content hr {margin-bottom: 0;}

          And change around line 277 to

          ol {list-style: decimal outside none; margin: 0 0 18px 2.5em; }

          I found this using the “Firebug” plugin for Firefox, where you can edit CSS options very conveniently and see their effect in real time. You can try it out too and make it even better looking :)

          Perhaps you’ll even find a way of changing the standard CSS code of WP-GeSHi-Highlight to make things look good again, so that you don’t have to change the CSS of your theme. In this case, please let me know how you made it :)

  69. Jesse Bye Avatar

    Hi Jan-Philip,
    I would really like to use your plugin, but for some reason I’m unable to get it running on my WP 3.0.4 installation. I added and activated the plugin, but when I add the lang=”” argument to some code, it doesn’t get formatted. On my example page, you can see that neither the CSS or JS get added to the header. Am I missing something? Is there more that I need to do to get it running besides installing and activating it?

    Thank you so much for your hard work and help.

    1. Jan-Philip Gehrcke Avatar

      Hey Jesse,

      sorry for the late reply. It’s difficult to diagnose the problem remotely. I assume you’re not using the visual editor for your posts and it seems that the HTML you’re writing goes to the output without further filtering. My first guess ist that there might be an incompatibility with another plugin you are using.

      Could you take this approach and see if you find an incompatibility by deactivating this or that plugin?

      Let’s see where this goes.. :-)

  70. Uli Avatar

    Thanks, that fixed it!

    Thanks for the plugin! I have another thing for you ;) When having the same type of sourcecode on the same page, the CSS for the highlighting is generated over and over again in the sourcecode although it’s completely identical (e.g. .bash is definied 10 times if pre lang=”bash” is used 10 times in the post). Would it be possible to push this only once to the output?

    Thanks in advance!

    Best Regards,

    1. Jan-Philip Gehrcke Avatar

      Hello again :-)

      Yes, I know about this and it makes me feel somehow uncomfortable, too. The reason is that every code block is processed individually, without looking to the left or to the right. Until now I thought about it like this: more intelligence requires more effort — which affects the performance for every single page request containing code to highlight negatively. This should be the case. To be sure, I have to look deeper into GeSHi again. Maybe there is some way without losing performance.

      So, yeah… I have some very vague ideas how to implement more intelligence to prohibit duplicate pieces of CSS code. If I have time, I will check it out and see how much performance this actually costs. Then, I’ll make some decision :-)

      Thanks for your comment!

      1. Jan-Philip Gehrcke Avatar


        I just modified the plugin in a way, so that CSS code for one specific language is only printed once, but then entirely without further optimization adjusted to your actual piece of code. This way, the CSS code can be used for other code blocks using the same language on the same page, too. Hence, duplicate code output is prevented.

        Let me show it to you here :-)

        find . -name "rofl" | grep lol
        ls -ahl
        import os
        for foo in bar:
            print [a.stfu for a in foo if foo in bar]
        1. Uli Avatar

          Hello Jan-Philip,

          now it’s perfect :) That reduced the size of some of my pages a lot as i used many code examples :)

          Thanks for the great support!

          Best Regards,

  71. Uli Avatar


    when using the Plugin in Version 1.0.2 on WordPress 3.1 with Theme Arras, the comments on the articles are not showing up. With 1.0.1-beta it works without changing anything else.

    Best Regards,

    1. Jan-Philip Gehrcke Avatar

      I am very sorry for this big one. Argh. I did my tests, but obviously I performed them much to briefly. Sorry! And thank you very very much for reporting this!

      I just uploaded version 1.0.3 which fixes this problem.