Adding edit link to admin bar as sub menu
-
Hello,
I have a page where two posts are fetched and both are of custom type.
- The actual singular page with content. (post id #460)
- A testimonial shown in footer is also stored as custom post is also fetched. (post id #505)
Now the requirement is to show ‘Edit’ option as sub menu in admin bar. I tried to do this via this this code:
/** * Add sub menu item to admin bar */ function custom_admin_bar_render() { global $wp_admin_bar; global $post; if ( is_single() ) $wp_admin_bar->add_menu( array( 'id' => 'edit', //here define the name of parent under which this link is required to appear 'parent' => 'new-content', 'title' => __( 'Edit'), 'href' => get_edit_post_link($post->id) ) ); } add_action( 'wp_before_admin_bar_render', 'custom_admin_bar_render' );
I see it adds a sub menu item under + New but it links to Testimonial shown in footer (post id #505), while I want it to link to actual singular page (post id #460).
As per my understanding, it is doing this because footer post is called later and when this action ‘custom_admin_bar_render’ is processed, it gets details of post for testimonial.
Is there any way through which I can access the post object called before the testimonial in footer?
Thanks.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Adding edit link to admin bar as sub menu’ is closed to new replies.