Categories
General

WordPress Post Bookmarklet: a fix for ‘Press This’

I love WordPress and there is no reason not to. I also love bookmarklets. A bookmarklet is a piece of JavaScript code that execute whenever you click it in your browser. Bookmarklets normally live in your browser's bookmark toolbar and form a way of further customizing its functionality without an over-the-top amount of code.

Bookmarklets are great for sharing and curation. Facebook, Tumblr and others provide them, essentially popping open a new browser window on their site, giving you the ability to comment and then post a link to the currently viewed content. WordPress has a tool for that built in, 'Press This'.  Only problem is that it often times breaks and leads to a 404 error page. It appears the issue stems from the encoding of the protocol portion of the URL (e.g. http://, https:// etc.). It appears that a truly minor tweak can fix this issue. All you need to do is modify the JavaScript code in the 'Press This' bookmarklet generated by your WordPress blog.

For example, the original code is:

javascript:var d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f='http://<YOUR BLOG URL>/wp-admin/press-this.php',l=d.location,e=encodeURIComponent,u=f+'?u='+e(l.href)+'&t='+e(d.title)+'&s='+e(s)+'&v=4';a=function(){if(!w.open(u,'t','toolbar=0,resizable=1,scrollbars=1,status=1,width=720,height=570'))l.href=u;};if (/Firefox/.test(navigator.userAgent)) setTimeout(a, 0); else a();void(0)

with

javascript:var d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f='<YOUR BLOG URL>/wp-admin/press-this.php',l=d.location,e=encodeURIComponent,u=f+'?u='+e(document.location.host + document.location.pathname)+'&t='+e(d.title)+'&s='+e(s)+'&v=4';a=function(){if(!w.open(u,'t','toolbar=0,resizable=1,scrollbars=1,status=1,width=720,height=570'))l.href=u;};if (/Firefox/.test(navigator.userAgent)) setTimeout(a, 0); else a();void(0)

Try it out. Tell me if it works.

Share

12 replies on “WordPress Post Bookmarklet: a fix for ‘Press This’”

Leave a Reply

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

 

Share