Search

code indentation in wordpress

code indentation in wordpress

If, like me, you are a developer and occasionally put snippets of code on your wordpress blog you will no dount have found out that the <code> tag strips out the indentation and makes the resulting post very difficult to read.

The solution is to use the <pre> tag which will keep the indentation.

An example showing both <code> and <pre>:

Using <code>:
<?php
$d = "labby.co.uk";

if($d == "code indentation example")
{
echo "Thank you for not bothering to look at my example code";
}
else
{
echo "Hey, someone actually followed my code logic";
}
?>

Using <pre>:

<?php
  $d = "labby.co.uk";

  if($d == "code indentation example")
  {
    echo "Thank you for not bothering to look at my example code";
  }
  else
  {
    echo "Hey, someone actually followed my code logic";
  }
?>

Using <pre> and <code> together:

<?php
  $d = "labby.co.uk";

  if($d == "code indentation example")
  {
    echo "Thank you for not bothering to look at my example code";
  }
  else
  {
    echo "Hey, someone actually followed my code logic";
  }
?>

Now I just have to through all my posts and comments and convert them manually :(

Related posts

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.