navigation - Adding direct link to post editor in admin menu

admin2025-01-07  4

I'm trying to make a shortcut in navigation that will take user to one certain post. So far I'm using

add_action('admin_menu', 'add_custom_menu_position');

function add_custom_menu_position() {
add_menu_page('FeaturedJobs', 'Featured Jobs', 'edit_posts', 'edit.php?post=706&action=edit',18); 
}

The item does show up in the admin menu, but every time I try to use it, it inserts admin? as a part of the link and I get You do not have sufficient permissions to access this page. error.

The final link looks like this: http://website_url/wp-admin/admin.php?page=post.php?post=706&action=edit

I know that I have enough capabilities to edit it, because I'm on an admin account and also once I use a regular edit link (http://website_url/wp-admin/post.php?post=706&action=edit), it works fine. I'm rather sure the problem is there because the link I'm trying to reach is wrong, but I can't find a way to link to it in any other way.

I'll be grateful for any hints, E.

I'm trying to make a shortcut in navigation that will take user to one certain post. So far I'm using

add_action('admin_menu', 'add_custom_menu_position');

function add_custom_menu_position() {
add_menu_page('FeaturedJobs', 'Featured Jobs', 'edit_posts', 'edit.php?post=706&action=edit',18); 
}

The item does show up in the admin menu, but every time I try to use it, it inserts admin? as a part of the link and I get You do not have sufficient permissions to access this page. error.

The final link looks like this: http://website_url/wp-admin/admin.php?page=post.php?post=706&action=edit

I know that I have enough capabilities to edit it, because I'm on an admin account and also once I use a regular edit link (http://website_url/wp-admin/post.php?post=706&action=edit), it works fine. I'm rather sure the problem is there because the link I'm trying to reach is wrong, but I can't find a way to link to it in any other way.

I'll be grateful for any hints, E.

Share Improve this question asked Aug 24, 2015 at 16:00 EntalpiaEntalpia 1212 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 0

When you are adding the menu slug as edit.php?post=706&action=edit, it is adding in the url after admin.php considering it as a new page in admin dashboard (general behaviour of add_menu_page())

So, you should give a fully qualified url instead. I think, admin_url() should help.

Try adding

admin_url('post.php?post=706&action=edit')

Or

admin_url('edit.php?post=706&action=edit')

instead of

edit.php?post=706&action=edit

as menu slug.

add_action( 'admin_menu', 'register_custom_menu_link' );

function register_custom_menu_link(){
    add_menu_page('FeaturedJobs', 'Featured Jobs', 'edit_posts', 'featured_jobs', '__return_null', 'dashicons-external', 18);
}

add_action( 'admin_init', 'redirect' );
function redirect() {
    if(!empty($_GET['page']) && $_GET['page'] == 'featured_jobs') {
        // Your post id
        $post_id = 706;
        wp_redirect(wp_specialchars_decode(get_edit_post_link($post_id)));
    }
}

I was running into the same issue but was able to accomplish this with the help of wp_redirect and this post.

My solution ended up looking something like this:

add_action('admin_menu', 'add_custom_menu_position');

function add_custom_menu_position() {
$hook = add_menu_page('FeaturedJobs', 'Featured Jobs', 'edit_posts', 'featured-jobs',18); 
add_action('load-' . $hook, function () {
            wp_redirect(admin_url('post.php?post=706&action=edit'));
        });
}
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736257956a477.html

最新回复(0)