Support » Plugins » Hacks » Modify "Press This" body template

  • Resolved Pawel



    By default, when I use “Press This” bookmarklet on a website, I get standard template within post body:

    <p><a href=''>WordPress › Blog Tool, Publishing Platform, and CMS</a>.</p>

    I would like to style this a bit with CSS and perhaps change how it handles links as I am using Markdown language in my WP. So my question is: can I change default “Press This” bookmarklet behaviour so I can, for example, add a <div> around the link?

    Thanks in advance!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Is there really no way to do this? 🙁

    I have the same question, actually… anything is possible… did you figure it out yet?

    To be honest, I forgot about this topic 🙂 I haven’t figured it out but when I saw your post, I decided to give it a try on my own.

    Turns out, the file that is handling Press This behaviour is located at wp-admin/press-this.php. It’s quite a long file but editing it is relatively straightforward.

    Before you edit it, DUPLICATE IT. You don’t want to be downloading whole new WordPress package for a single 26KB file should anything go wrong.

    First, head to lines 102-105:

    if ( ! empty($selection) ) {
    $selection = preg_replace('/(\r?\n|\r)/', '</p><p>', $selection);
    $selection = 'ThisWillAppearBeforeSelectedText' . str_replace('<p></p>', '', $selection) . 'ThisWillAppearAfterSelectedText';

    Here you can replace what is being placed before and after the “quoted” text (if you select some text on a site and click the Press This bookmarklet, WordPress will automatically paste it into the editor for you). Simply edit ThisWillAppearBeforeSelectedText and ThisWillAppearAfterSelectedText (‘apostrophes’ must stay as they are).
    If you want to make it Markdown-style, replace the first string with ‘> ‘ and make the second string empty.

    Now, to style the rest, head to lines 601-612:

    $content = 'ThisWillApearBeforeAnythingElse';
    if ( $selection )
    $content .= $selection;
    if ( $url ) {
    $content .= 'ThisWillAppearBeforeTheLink';
    if ( $selection )
    $content .= __('ThisIsTheVIAString');
    $content .= sprintf( "[%s](%s)", esc_url( $url ), esc_html( $title ) );

    I think this is pretty self-explanatory. You can edit the way link is displayed on the last paragraph (sprintf). I’ve “Markdowninfied” it but you can edit it as you want.
    If you want to wrap all of the text generated by Press This in a div, use the ThisWillApearBeforeAnythingElse string.

    In general, the best way to see how it works is to play with it 😉

    Because this file is located in wp-admin directory, it is probably going to be replaced with each update. Bear that in mind.

    Hope it helps!
    (it helped me)

    Moderator Jan Dembowski


    Brute Squad and Volunteer Moderator

    NO! Don’t edit the files that ship with WordPress or encourage other people to do so!

    That will lead to an unsupportable WordPress installation, your changes will be lost at the next update, and will possibly create a security risk for that installation.

    The Press This portion can be reproduced with a plugin, there is no need to edit core files.

    Oh, ok. My bad. Can you edit/remove my post? I don’t want to mislead anyone (now that I see what I’ve done).


    Moderator Jan Dembowski


    Brute Squad and Volunteer Moderator

    Nope, it’s all good. You just fixed it with that reply. 😉

    Ok 🙂

    By the way, do you have any particular plugin in mind? I couldn’t find any.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Modify "Press This" body template’ is closed to new replies.