Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

How can I remove the 'Add New' button from a custom post within WordPress?

I have added the following code to my functions.php, so that I could remove the 'Add New' button. The code has worked...to an extent. It removes the button from the dark grey admin bar to the left, just under the custom post type. However, when you lick into the post and view the list of posts, another 'Add New' button is there. Also, when you click into the individual post, yet another 'Add New' button is there.

I want to set up the custom post, so that there is only one post, and you can go in and edit that singular post, without the option to add a new post. How can I achieve this?

function disable_new_posts() {
// Hide sidebar link
global $submenu;
unset($submenu['edit.php?post_type=CUSTOM_POST_TYPE'][10]);

// Hide link on listing page
if (isset($_GET['post_type']) && $_GET['post_type'] == 'CUSTOM_POST_TYPE') {
    echo '<style type="text/css">
    #favorite-actions, .add-new-h2, .tablenav { display:none; }
    </style>';
}
}
add_action('admin_menu', 'disable_new_posts');

Thanks in advance :)