WordPress Admin – Removing ‘Add New’ on Page template

I’m working on a networked WordPress site at the moment. Part of the task is to create a theme for the subsites within the network that the Super Admin can activate and automatically cause the admin panel for the subsite to be fully configured. This means that not only are the menu options all customised (with many removed) but the default WordPress page, post and comment are all customised. There is also an additional page called ‘Gallery Page’ created automatically when the theme is activated. Less admin overhead, a new subsite can be created and configured in a couple of clicks.

The one thing that was annoying me is that there is an additional ‘Add New’ link in page and post templates in WordPress. That’s fine normally but I am crippling the users capacity to add new pages in this install. Easy to remove the option from the Pages submenu, but where is the template link located?

Answer: /wp-admin/edit.php on line 189 (v3.2.1)

Just remove the following line;

<a href="<?php echo $post_new_file ?>" class="add-new-h2"><?php echo esc_html($post_type_object->labels->add_new); ?></a>

It will cause the link to be removed on both the Pages and Posts, but you would retain the Add New submenu in the Posts drop-down and direct the users to that in your system documentation.

It’s not the end here though. If the user clicks on a Page or Post to edit it, they will be presented with yet another ‘Add New’ link (is there no end to them!!). This one lives in wp-admin/edit-form-advanced.php at line 198.

<a href="<?php echo esc_url( $post_new_file ) ?>" class="add-new-h2"><?php echo esc_html($post_type_object->labels->add_new); ?></a>

Of course removing the links isn’t the same as changing the WP capabilities, but it is a quick method of customising the subsite admin panel quickly.

Just as an aside, thanks to Krishna Kant Sharma (http://www.krishnakantsharma.com) for his technique to fake a ‘Theme Activation’ hook and trigger a function to run once when the theme is activated.

The code below is placed in functions.php and creates the new ‘Gallery Page’ post when the theme is activated. It creates and options

function wp_register_theme_activation_hook($code, $function) {
    $optionKey="theme_is_activated_" . $code;
    if(!get_option($optionKey)) {
        call_user_func($function);
        update_option($optionKey , 1);
    }
}

function craft_activate() {
     // Code to add new Gallery page on activation of theme.
		$gallery_content = sprintf( __( "This is your Gallery Page.  Follow the instructions in the tutorial to add your images. " ), admin_url() );
		$gall_array = array(
			'post_author' => $user_id,
			'post_date' => $now,
			'post_date_gmt' => $now_gmt,
			'post_content' => $gallery_content,
			'post_excerpt' => '',
			'post_title' => __( 'Gallery Page' ),
			'post_name' => __( 'gallery-page' ),
			'post_modified' => $now,
			'post_modified_gmt' => $now_gmt,
			'guid' => $first_post_guid,
			'post_type' => 'page',
			'to_ping' => '',
			'pinged' => '',
			'post_status' => 'publish',
			'post_content_filtered' => '');
						
		// Insert the post into the database
		wp_insert_post( $gall_array );
	 
 }

wp_register_theme_activation_hook('craftactive', 'craft_activate');

Leave a Comment