Skip to content

Instantly share code, notes, and snippets.

@n8kowald
Last active November 18, 2022 04:11
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 n8kowald/970e9614d374a9bca4384ffe765c8515 to your computer and use it in GitHub Desktop.
Save n8kowald/970e9614d374a9bca4384ffe765c8515 to your computer and use it in GitHub Desktop.
Edit current WordPress Post or Page
javascript:(function () {
const pageOrPostClass = Array.from(document.body.classList).filter(function (item) {
return item.includes("page-id-") || item.includes("postid-");
});
const id = pageOrPostClass.length ? pageOrPostClass[0].replace(/page-id-|postid-/, '') : 0;
if (!id) {
alert('No WordPress post found');
return;
}
let wpDomain = document.querySelector('link[rel="https://api.w.org/"]');
if (wpDomain && wpDomain.href) {
wpDomain = wpDomain.href.replace('/wp-json/', '');
} else {
wpDomain = document.location.origin;
}
window.location.href=`${wpDomain}/wp-admin/post.php?action=edit&post=${id}`;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment