wpPro offers design, development and full-service professional WordPress hosting service for serious bloggers web design web development professional WordPress hosting

wpPro offers design, development and full-service professional WordPress hosting service for serious bloggers

How to Make your Codes “Friendly”

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

Have you found yourself wanting to display a piece of code in your blog post or a comment form that left you stripping off elements or re-pasting it over and over only to find that the code is actually being executed? I run in this issue a lot while replying to support questions, so I conveniently remove the “<” and “>” of all HTML tags and PHP scripts to allow the codes to to be displayed without execution, this however cause more harm than help to the novice user and the experience is never that pleasant. Help is finally here!
A combination of using the “code” tag and converted the base code by using converters like Postable makes for a delightful toll that allows users to share, copy and paste codes without any hassles and guesswork. Here’s how you go about it.

  1. Copy your code (HTML or PHP or whatever else) and paste it in the Postable post area (which at first will read “For your copy-and-pasting pleasure.”).
  2. Click the “make me friendly” button
  3. The code is converted to characters, for example < will be converted to & l t ;
  4. Copy the characters and past it on your blog post or comment within code tags
  5. That’s it.

In order to demonstrate how it works, I have copied and pasted a piece of code from one of our latest themes below using Postable conversion:


<?php if (have_posts()) :?>
<?php $postCount=0; ?>
<?php while (have_posts()) : the_post();?>
<?php $postCount++;?>
<div class="entry entry-<?php echo $postCount ;?>">
<h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<p class="meta">
Posted <?php the_time('m.d.Y'); ?> at <?php the_time('g:i a') ?> in <?php the_category(', ') ?><?php if (function_exists('the_tags')) { ?><?php the_tags(', ', ', ', ''); ?><?php } ?> received <strong><?php comments_popup_link('Have your say »', '1 Comment »', '% Comments »'); ?></strong>.
</p>

The code is then displayed in a format that can be copied and pasted and never executed. Works fine to me!

Update: Two other tools of significant use are SimpleCode by Dan Cederholm which I have adopted as part of the comment form on this site and elsewhere and the user submitted Asciible converters!

07.11.2007 - 6:19 pm - Design, PHP, Projects, Tips, WordPress - 120 views -

2 Responses to “How to Make your Codes “Friendly””

  1. 2
    Jeremy Martin Says:

    Hey - I just went live with my own version of an ascii encoder as well. It uses regular expressions on the client side, so it is extremely fast. It also provides several options for customizing the output. Let me know what you think!

    http://www.jeremymartin.name/projects.php?project=asciible

  2. 1
    rey Says:

    hi

Leave a Reply