General12 Comments
28
Mar 11

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.


04
Oct 09

Broken WordPress theme can hurt: This is how to recover.

If you ever install a WordPress theme that causes you to see blank screens for both the admin (!) and the blog itself, do this:

Go to your Worpdress installation directory, and rename the offensive theme’s directory to something else. WordPress will detect the problem and revert to the original theme. You can then access the blog’s administrative area again.

Thanks to this post.


27
Aug 09

Fix WordPress ‘Press This’ 404 error

Apparently WordPress has a newfangled bookmarklet (newfangled to me) that allows you to quickly post about stuff you love. Bookmarklets are awesome, btw. But it did not work, most likely because I use the search-friendly, meaningful URLs. The post I Googled gives you an idea into how to fix it but it did not work for me. Try this code instead of the one he mentions, and follow his instructions:

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://www.YOURDOMAINHERE.com/wp-admin/press-this.php',l=d.location,yz=l.href.replace(///g,'\/'),e=encodeURIComponent,g=f+'?u='+e(yz)+'&t='+e(d.title)+'&s='+e(s)+'&v=2';function a(){if(!w.open(g,'t','toolbar=0,resizable=0,scrollbars=1,status=1,width=720,height=570')){l.href=g;}}setTimeout(a,0);void(0);

Enjoy.