I find that more and more on this blog I am displaying code in posts. To be honest I never really knew how to do it properly so in the interest of time I would just create an image with code snippets, or link to an external text file. I don't like either method. I'd prefer to show the code within the posts and allow it to be copy-n-pastable.
I found this post just now which discusses displaying code in WordPress posts. It says you can manually convert angle brackets to character entities. It also talks about some plugins, one in which will convert the brackets, etc. for you when you wrap them in code tags. So, here's my live test of WP_CodeShield...
<strong>This better not be bold</strong>
<em>This better no be italicized</em>
<?php
$testvariable = 'Might as well test if I can display php code as well';
echo $testvariable;
?>
Results:
Well.. clearly it worked. I like how the plugin converts the code within the post just one time rather than converting on-the-fly for each view. That way it is not dependent on the plugin to work after the initial conversion. And it really beats doing the conversions manually.
Related posts:













Enter your first name and email address below to receive exclusive money making tips.






Thu, Jun 10, 2010
Blogging