[wp-trac] [WordPress Trac] #62074: Hooks to remove Add New links (was: wp_admin_bar_new_content_menu issue)
WordPress Trac
noreply at wordpress.org
Wed Sep 18 17:48:30 UTC 2024
#62074: Hooks to remove Add New links
-----------------------------+------------------------------
Reporter: markuscode | Owner: (none)
Type: feature request | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Administration | Version:
Severity: normal | Resolution:
Keywords: | Focuses:
-----------------------------+------------------------------
Changes (by sabernhardt):
* component: Toolbar => Administration
Comment:
The toolbar link can be removed already by setting the custom post type's
`show_in_admin_bar` parameter to `false` (either in
[https://developer.wordpress.org/reference/functions/register_post_type/#parameters
register_post_type] or
[https://developer.wordpress.org/reference/hooks/register_post_type_post_type_args/
register_{$post_type}_post_type_args]).
To **edit** the toolbar link, you could use the
`wp_before_admin_bar_render` hook.
{{{#!php
<?php
function replace_new_cpt_in_admin_bar() {
global $wp_admin_bar;
$node = $wp_admin_bar->get_node( 'new-cpt' );
// Return early if node contents are not available to edit.
if ( ! isset( $node->title ) ) {
return;
}
$wp_admin_bar->add_node(
array(
'id' => 'new-cpt',
'title' => 'New Custom Post Type link text',
)
);
}
add_action( 'wp_before_admin_bar_render', 'replace_new_cpt_in_admin_bar'
);
}}}
Removing a `.page-title-action` link seems more complicated. If hiding the
link is good enough, you could add custom admin CSS with
`admin_enqueue_scripts` (or with a plugin such as
[https://wordpress.org/plugins/custom-css-js/ Simple Custom CSS and JS]):
{{{
.post-type-cpt .page-title-action {
display: none;
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/62074#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list