最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Is it possible to use add_submenu_page() to add an item that's a link to edit another page?

programmeradmin0浏览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?

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?

Share Improve this question asked Oct 13, 2016 at 10:51 Jonny PerlJonny Perl 2961 silver badge8 bronze badges 2
  • 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 Commented Oct 13, 2016 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 Commented Oct 13, 2016 at 14:22
Add a comment  | 

1 Answer 1

Reset to default 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')

} );
发布评论

评论列表(0)

  1. 暂无评论