3

In Admin, is there any way to use a slug instead of a post ID# within the URL that takes you to a post's edit screen.

So instead of:

http://example.com/wp-admin/post.php?post=5562&action=edit

You would use something like:

http://example.com/wp-admin/post.php?slug=home&action=edit

Or, since the database stores the slug in the column post-name:

http://example.com/wp-admin/post.php?post-name=home&action=edit

Of course, neither of these actually works. Is there some existing method for doing this using Wordpress' built-in URL parameters?

If not, what sort of function could be used in my theme's functions.php file that would make this work?

  • slugs aren't necessarily unique, so this would be prone to failure. why do you want to do this? what problem are you trying to solve? – Milo Dec 17 '14 at 19:01
  • That's interesting, because I thought slugs were unique. I've often encountered a situation where I unknowingly created a post with the same title, and the slug generated appended with a number like '-2'. Anyway, I have a quick link to edit my home page created using Admin Menu Editor, but I had to duplicate and revise it, making the duplicate into the home page. I deleted the old one and changed the slug for the new one to 'home' (like the old one had). Of course, now my quick link no longer works. I'd like a link that always goes to edit page for my 'home' page, no matter what the ID is. – cvc Dec 17 '14 at 19:06
  • slugs only have to be unique within a post type on the same level of hierarchy. if you want something like you describe, direct your request to admin-post.php, do your lookup, and redirect to the normal admin url for that post. – Milo Dec 17 '14 at 19:13
  • 1
    How would you handle post revisions? Also why would you want this? Users shouldn't notice the URLs in the admin panel, are you trying to manually construct edit urls? – Tom J Nowell Dec 17 '14 at 19:35
  • This may be a fringe case, Tom... – cvc Dec 18 '14 at 18:13
0

If the home page is set as "Home" in settings, use:

get_edit_post_link( get_option( 'page_on_front' ) );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.