0

Morning all, I'm having a bit of trouble finding a function I can use to link to a post type from the admin area. I'm actually using something as simple as:

<a href='edit.php?post_type=slides'>Slides</a>

in another area, but didn't know if there was a better way of handling it (since I'm still technically hardcoding in the first part of the URL). The post type name being hardcoded isn't the issue, really just generating that first part of the URL. Thanks!

1 Answer 1

2

The following should do the trick:

  <a href=" <?php admin_url('edit.php?post_type=slides') ?>">Slides</a>

It's how it's done in the source code. The function admin_url() appends the proper admin address. The output of the url should be:

http://www.mysite.com/wp-admin/edit.php?post_type=slides 
2
  • Awesome! One last part - if I am displaying this type of link within an array, do you know how I'd properly encode that to not escape the array value? "desc" => "Enable either a static main image or a dynamic slideshow populated by the <a href='admin_url(edit.php?post_type=slides)'>Slides</a> content type", Banging my head against the wall with this part. Thanks!
    – Zach
    Commented Nov 30, 2011 at 15:24
  • Ah - figured this one out by myself - if it's useful to anyone else - I just set the content type link as a variable and then spit that out in the array statement: $slides_link = '<a href="'.admin_url("edit.php?post_type=slides").'">Slides</a>'; "desc" => "Enable either a static main image or a dynamic slideshow populated by the $slides_link content type", Thanks again for the help!
    – Zach
    Commented Nov 30, 2011 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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