Improving “Press This” in WordPress

In a previous post, I said I’d be looking for a way to change the Press This functionality in WordPress so that it wrapped the inserted content in a div – which allows me to style it.     After a bit of firtling around in the code, it’s actually quite simple - assuming you’re using the WordPress.org software.  If you’re on WordPress.com, you won’t have access to this stuff.

In the current version of Press This (press-this.php in your wp-admin directory), at line 601, there is the PHP statement

$content = '';

and at line 614 you’ll find

remove_action( 'media_buttons', 'media_buttons' );

Replace that whole section of code (including the lines quoted) with the following:

$content = '';
 if ( $selection )
  $content .= "<div class='quotedcontent'>$selection";
 if ( $url ) {
    $content .= '<p>';
    if ( $selection )
       $content .= __('via ');
    $content .= sprintf( "<a href='%s'>%s</a>.</p>", esc_url( $url ), esc_html( $title ) );
 }
 if ($content != '')
    $content .= "</div>";
 remove_action( 'media_buttons', 'media_buttons' );

All this is doing is putting the div tags before the content you pulled in via Press This, content at the start, and after the URL (if there is one).

Now, when Press This is used, the whole of the inserted content will be in a div with the class ‘quotedcontent’.   So that just leaves you to style it in your CSS file.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>