Is it possible to have dynamic post id # in add_menu_page()?

Question

I use the add_menu_page function in my custom theme builds but when I export my local copy of the site and import it in the production site some of post id numbers change and I have to update this function manually (ie: in the code below: ?post=8, ?post=8, ?post=10). Is there a way to have these numbers be dynamic?

function custom_admin_menu_links() {
    $user = wp_get_current_user();
    if ( ! $user->has_cap( 'manage_options' ) ) {
        add_menu_page( 'Home', 'Home', 'edit_posts', 'post.php?post=6&action=edit', '', 'dashicons-admin-home', 1);
        add_menu_page( 'About', 'About', 'edit_posts', 'post.php?post=8&action=edit', '', 'dashicons-id', 2);
        add_menu_page( 'Contact', 'Contact', 'edit_posts', 'post.php?post=10&action=edit', '', 'dashicons-phone', 3);
    }
}
add_action( 'admin_menu', 'custom_admin_menu_links' );

--------------------------------------------------

>>> Share a link to this question, just copy and paste the code bellow on your web page <<<

<a href="https://www.wptricks.com/question/is-it-possible-to-have-dynamic-post-id-in-add_menu_page/">

Is it possible to have dynamic post id # in add_menu_page()?</a>
0
, , , codeview 2 weeks 0 Answers 21 views 0

Leave an answer