WordPress Sitemap Class for PHP 4

Please see WordPress Sitemap Class for the main write-up and code examples.

The class file is slightly different to cope with PHP 4 limitations, but with the same class features. There’s one main difference in it’s usage, and that it that methods can’t chain together:

require_once 'classes/GT_Sitemap.php';
$sitemap = new GT_Sitemap;
$sitemap->setOrder('posts', 'pages');

View the code

WordPress Sitemap Class

A sitemap for a website is basically a single place that links to all the other pages (and posts) on that site, so human visitors can scan through to find what it is they may be after. The XHTML sitemap to which I refer is not the sitemap.xml that Google and other search engines support, which also includes values on how often those pages should be visited by their spiders.

You could add a normal page, and manually add a link every time you create a new post or page, but of course, there are more efficient ways of doing it. I’ve already offered examples on how this may be done programatically within the Thesis theme but even this could be improved upon, and made more generic to apply to any theme, by using a WordPress shortcode instead.

View the code

Permalink Shortcode on WordPress

Adapted from Added Permalinks Shortcode on WordPress.

function do_permalink($atts) {
		'id' => 1,
		'text' => ''
    ), $atts));

    if ( '' == $text ) {
      $text = get_the_title($id);

    return '<a href="' . get_permalink($id) . '?phpMyAdmin=405d0e49429889b5fce2435c6318aeae">' . do_shortcode($text) . '</a>';

add_shortcode('permalink', 'do_permalink');


&#091;permalink id="140"]

will output: Permalink Shortcode on WordPress (as 140 is the ID of this post) which will always have the correct title.

Alternatively, specify the link text that won’t change:

&#091;permalink id="140" text="My custom link text"]

which output as:My custom link text.

Bio Shortcodes for WordPress

Need to add a load of bios (perhaps of your blog authors) to a single page in a consistent manner? Best to use a shortcode. Add the following to your theme’s functions file:

View the code

Syntax Highlighting Shortcodes in WordPress

  1. Install Easy Google Syntax Highlighter plugin.
  2. The actual highlighting library this plugin uses requires all sorts of markup and specially formatted classes to be used. It used to allow nice shortcodes, like [php], which you can re-enable. Add the following to your theme’s functions file:
// Stops WordPress from mangling our code.
// Be aware, you'll now need to explicitly include <p>...</p> tags for non-code text,
// which is why you won't see much of it here if I can help it 🙂
remove_filter('the_content', 'wpautop');
remove_filter('the_content', 'wptexturize');
remove_filter('the_content', 'convert_chars');
remove_filter('the_content', 'convert_smilies');
remove_filter('the_excerpt', 'wpautop');
remove_filter('the_excerpt', 'wptexturize');
remove_filter('the_excerpt', 'convert_chars');
remove_filter('the_excerpt', 'convert_smilies');

function php_shortcode_function($attr, $content = null) {
  return get_code_output('php', $attr, $content);
add_shortcode('php', 'php_shortcode_function');

function js_shortcode_function($attr, $content = null) {
  return get_code_output('js', $attr, $content);
add_shortcode('js', 'js_shortcode_function');

function html_shortcode_function($attr, $content = null) {
  return get_code_output('html', $attr, $content);
add_shortcode('html', 'html_shortcode_function');

function css_shortcode_function($attr, $content = null) {
  return get_code_output('css', $attr, $content);
add_shortcode('css', 'css_shortcode_function');

function get_code_output($brush, $attr, $content) {

  extract( shortcode_atts( array(
      'autolinks' =&gt; 'true',
      'classname' =&gt; '',
      'collapse' =&gt; false,
      'firstline' =&gt; 1,
      'gutter' =&gt; 'true',
      'highlight' =&gt; '',
      'htmlscript' =&gt; false,
      'light' =&gt; false,
      'smart-tabs' =&gt; 'true',
      'tabsize' =&gt; 4,
      'toolbar' =&gt; 'true',
      'wraplines' =&gt; 'true'
      ), $attr ) );

  $output = '<pre>' . str_replace('&lt;&#039;, &#039;&lt;&#039;, do_shortcode($content)) . &#039;</pre>';

  return $output;

Now you can use the [php] shortcode and add your full code (no need to escape those < characters). Same goes for for the other shortcodes added ([plain], [html], [js], [css] etc). The shortcodes also support attributes (like highlighting of a line) as per the Syntax Highlighter Parameters.

The above code will be edited as I edit the underlying code for this site to allow for all of the Syntax Highlighter parameters. This is all very meta…