SEO Tips & Tricks: They Don’t Want You to Know About

Source Code Snippets

by John H. Gohde on October 12, 2008

Putting something as simple as PHP source code into a post is a bit of a major project in Wordpress. While there is a manual way of doing this. The easy way is to use what is called a syntax highlighter plugin. John H. Gohde has settled upon using Dean’s Code Highlighter on his blog.

John has reviewed 3 or 4 different syntax highlighters and settled upon Dean’s Code Highlighter for offering more of what he wanted in a source code lister.

 

Dean’s Code Highlighter

All so typically, this plugin offers next to no instruction on how to use it.

First, of all, you have to disable the WYSIWYG Visual Editor before using this plugin. The visual editor in Wordpress will actually destroy your source code. Disabling the visual editor is how most of these source code highlighter plugins work.

After installing the plugin, you have to check out the Code Highlighter options in the Wordpress Settings Tab. Basically, you have to decide if you want all of your source code listings to be with or without line numbers. This is a major weakness of Dean’s plugin, as some of the others let you make that choice, code snippet by code snippet.The default option is to show numbers, which on the theme being used by this blog at least does not display properly.

With this plugin, you simply enclose your code snippet with the standard <pre> tags, as follows.

<pre lang="php">
Source Code
</pre >
 

A typical listing for PHP code is rather colorful due to this plugin’s use of GeSHi – Generic Syntax Highlighter. What Dean has done is basically provide a front-end interface to all of the real work that is being done by GeSHi.

The plugin works with many different programming languages, such as css, javascript, perl, php, and html4strict.

<?php if  (is_home()) { ?>
   <?php _e(‘Home’); ?>
<?php } elseif (is_page()) { ?>
   <?php _e(‘Page’); ?>
<?php } elseif (is_single()) { ?>
   <?php _e(‘Post’); ?>
<?php } else { ?>
   <?php _e(‘Bye’); ?>
<?php } ?>
 

Dean’s plugin offers no flexibility to the formatting of the required <pre> tags. Leave a trailing space and your code listing will go blank. Add an extra parameter, such as “1″, after the lang parameter and the colorful colors will disappear.

<pre lang="php" "1">
<?php if  (is_home()) { ?>
   <?php _e(’Home’); ?>
<?php } elseif (is_page()) { ?>
   <?php _e(’Page’); ?>
<?php } elseif (is_single()) { ?>
   <?php _e(’Post’); ?>
<?php } else { ?>
   <?php _e(’Bye’); ?>
<?php } ?>
 

John H. Gohde liked Dean’s Code Highlighter because it avoided the use of a horizontal scroll box since the plugin offers automatic text wrapping. In addition, most of the other syntax highlighter plugins did not display properly on John’s custom theme.


[tags]John H. Gohde, plugin, PHP, code snippets, conditional tags, theme template[/tags]




Author: John H.Gohde









You can leave a comment, or trackback from your own site.



Then help our blog by linking to it. Simply copy and paste the code below into your website (Ctrl+C to copy)

It will look like this: Source Code Snippets


Digg It  Add To Delicious  Stumble This  Add to Technorati







Leave a Comment

Spam Protection by WP-SpamFree

 

Menu

» Source Code Snippets




Most Popular Posts

    None Found

 

 

Subscribe

Meta


Recent Posts

  1. All in One SEO
  2. Always Keyword Stuff Intelligently
  3. Always Link To Your Home Page
  4. Anchor Text – A Pandora’s Box

Copyright (C) 2008 - 2010 by John H. Gohde
All Rights Reserved.
Email | Site Map | Advanced Search