Pixel Envy

Written by Nick Heer.

Custom Press This, For Use With DFLL and Markdown

If you want to roll a “linked list”-style post format on a WordPress installation, you’re going to need a few plugins:

  1. PHP Markdown (do yourself a favour and grab the “Extra” version)
  2. Daring Fireball Linked List
  3. My custom press-this.php file (Updated June 14, 2012)

Install the first two as required. You can set up the DFLL plugin any way you want (I have mine set so that the post date is the permalink). To install my custom press-this.php file, you need to fire up your FTP client and navigate to /wp-admin/. Replace the press-this.php file in there with mine. I should probably mention at this point that you assume all liability, and that I won’t take any heat or blame if something gets messed up. Also note that from this point, you’ll have to keep a backup copy of that file and replace it any time you update WordPress.

What does my custom file do? Two main things. The first is that it replaces the WordPress-standard HTML quoting of a selection with Markdown-style quoting:


$selection = preg_replace('/(\r?\n|\r)/', "\n> ", $selection);
$selection = '> ' . str_replace('<p></p>', '', $selection) . '';

This seems kind of roundabout: taking an HTML string, converting it in PHP to Markdown so that it can later be converted via PHP back to HTML. It cleans up the post box, though, making for easier composing.

The second thing my file does is to change the order of text within a new post when using a selection:


$content = '';
if ( $url )
   $content .= sprintf( "<a href='%s'>%s</a>.\n\n", esc_url( $url ), esc_html( $title ) );
               
if ( $selection ) {
   $content .=  $selection;
}

This turns into the link (to be interpreted by DFLL), followed by two blank lines, followed by the selection as a block quote (as defined earlier).

Use responsibly. I assume no liability. The risk is yours.