Skip to content

Instantly share code, notes, and snippets.

@kellenmace
Created July 4, 2016 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kellenmace/61090fe78f6a4244b1d3f5434d8987bd to your computer and use it in GitHub Desktop.
Save kellenmace/61090fe78f6a4244b1d3f5434d8987bd to your computer and use it in GitHub Desktop.
WordPress Admin Switcher Bookmark - Just create a new bookmark, edit it, and paste all of this code into the "URL" field. Especially handy for logging in and switching to/from the admin on mobile devices.
javascript:function b(a){if(Object!=a.constructor||1>Object.keys(a).length)return!1;for(var M in a){var w=document.querySelectorAll(a[M]+" > a.ab-item[href]");if(0<w.length)return w[0].getAttribute("href")}return!1}function c(a){a.endsWith("/")||(a+="/");return a}var d=window.location.pathname;
if(-1<d.indexOf("/wp-admin/")||-1<d.indexOf("/wp-login.php")){var e;var f=b({view:"#wp-admin-bar-view",f:"#wp-admin-bar-preview",a:"#wp-admin-bar-site-name"});if(f)e=f;else{b:{var g={j:"/wp-admin/",o:"/wp-login.php"},h;for(h in g){var k=window.location.href.indexOf(g[h]);if(-1<k){f=window.location.href.substring(0,k);break b}}f=!1}e=f?f:window.location.origin}window.location=e}else{var l;var m=b({c:"#wp-admin-bar-edit",a:"#wp-admin-bar-site-name"});if(m)l=m;else{var n;c:{var p={i:'link[rel="stylesheet"][href]',
scripts:"script[src]",g:'link[type="application/rss+xml"][href]',s:'link[rel="pingback"][href]'},q;for(q in p){var r=document.querySelectorAll(p[q]);if(0<r.length)for(var t in r){var u;d:switch(q){case "scripts":u="src";break d;default:u="href"}var v;d:{var x={l:"/wp-content/",m:"/wp-includes/"},y=void 0;for(y in x){var z,A=r[t],B=A[u].indexOf(x[y]);if(z=-1<B?A[u].substring(0,B):!1){v=z;break d}}v=!1}if(v){n=v;break c}}}n=!1}var C,D=!1,E={b:"#comment_post_ID[value]",h:'link[rel="shortlink"][href]',
body:"body[class]"},F;for(F in E){var G=document.querySelectorAll(E[F]);if(0<G.length)switch(F){case "commentsForm":D=G[0].value;break;case "shortlink":c:{var H=G[0].getAttribute("href");if(!(-1<H.indexOf("//wp.me/"))){var I=H.indexOf("/?p=");if(-1<I){D=H.substring(I+4,H.length);break c}}D=!1}break;case "body":var J=G[0].getAttribute("class"),K=J.indexOf("postid-");if(-1<K)var J=J.substring(K+7,J.length),L=J.indexOf(" "),D=-1<L?J.substring(0,L):J;else D=!1}}C=D;if(n){var N=c(n)+"wp-admin/";C&&(N=
N+"post.php?post="+C+"&action=edit");m=N}else m=!1;l=m?m:c(window.location.origin)+"wp-admin/"}window.location=l};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment