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
0
jQuery(document).ready( function($) {      
    $('#toplevel_page_display_strategies ul li:nth-child(3)').addClass('current')
    $('#toplevel_page_display_strategies').removeClass('wp-not-current-submenu')
    $('#toplevel_page_display_strategies').addClass('wp-has-current-submenu')

} );
| improve this answer | |

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.