0

I've recently discovered add_submenu_page and was pleased to be able to add my own page under a specific post type. I'm using a callback function to output some HTML directly

/**
 * Display callback for the submenu page.
 */
function homeslides_ref_page_callback() { 
?><h1>Curate Social Media</h1> 
<iframe style="width:100%; height:100%;min-height:600px" src="/mypage">    </iframe>
<?php
}

I would now like to make a separate callback for other custom post types, but one that lets me effectively make a shortcut to edit a particular page. For example, I have a custom post type called Careers, and within Careers I'd like to add a menu item that links to the edit page for a separate page.

It's not immediately obvious to me how I'd do this - does anyone have experience of this?

  • 1
    You'd need to try this first, but I'm sure you can use an absolute URL as the $menu_slug argument with no callback e.g. add_submenu_page( 'parent-slug', 'Page Title', 'Menu Title', 'capability', get_edit_post_link( $post_id ) ); – TheDeadMedic Oct 13 '16 at 13:16
  • Thanks for the tip. This does indeed work, except that get_edit_post_link outputs an absolute URL, which is then appended to the domain. To get this to work, I had to replace out the hostname - ie. add_submenu_page( 'edit.php?post_type=work', 'Edit Work', 'Edit Landing Page', 'manage_options', str_replace($_SERVER['HTTP_HOST'],'',get_edit_post_link( $workpage->ID ) )); Thanks again! – Jonny Perl Oct 13 '16 at 14:22

Your Answer

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

Browse other questions tagged or ask your own question.