18

I've registered post type with following --

$holidayLabels = array(
    'name' => __( 'Holidays'),
    'singular_name' => __( 'Holidays'),
    'all_items' => __( 'All Holidays'),
    'add_new' => __( 'Add New Holiday'),
    'add_new_item' => __( 'Add New Holiday'),
    'edit_item' => __( 'Edit Holiday'),
    'new_item' => __( 'New Holiday'),
    'view_item' => __( 'View Holidays'),
    'not_found' => __( 'No Holidays found'),
    'not_found_in_trash' => __( 'No Holidays found in Trash'),
    'parent_item_colon' => ''

);

$holidayArgs = array(
    'labels'               => $holidayLabels,
    'public'               => true,
    'publicly_queryable'   => true,
    '_builtin'             => false,
    'show_ui'              => true,
    'query_var'            => true,
    'rewrite'              => array( "slug" => "holidays" ),
    'capability_type'      => 'post',
    'hierarchical'         => false,
    //'menu_position'        => 6,
    'supports'             => array( 'title'),
    'has_archive'          => false,
    'show_in_nav_menus'    => false,

);
register_post_type('holidays', $holidayArgs);

And I want to remove permalink that appears below title when I post new holiday or start editing existing one. enter image description here

I want to remove this because, holidays will be displayed in separate widget. I don't want admin to be able to see it as single post anyhow. There's no template defined for such.

3
  • Do you want them to have archive page and to be able to access them with permalink? Aug 1, 2013 at 18:46
  • @KrzysiekDróżdż no. that's why I want to remove permalink. There's no such page available. Holidays will be shown in widget itself and details with ajax in modal. Aug 1, 2013 at 18:50
  • So you should also take care of disabling permalinks, archives, and so on. Take a look at my answer ;) Aug 1, 2013 at 19:09

4 Answers 4

56

Well, there is another way. And better, I guess.

You should look at register_post_type parameters. You should probably set them like this:

'public' => false,  // it's not public, it shouldn't have it's own permalink, and so on
'publicly_queryable' => true,  // you should be able to query it
'show_ui' => true,  // you should be able to edit it in wp-admin
'exclude_from_search' => true,  // you should exclude it from search results
'show_in_nav_menus' => false,  // you shouldn't be able to add it to menus
'has_archive' => false,  // it shouldn't have archive page
'rewrite' => false,  // it shouldn't have rewrite rules

If post type is not public, then you won't see this part of editor.

2
  • Cheching the answer made by Krzysiek Dróżdż, Will this can be applied to custom taxonomies? PD: Sorry for posting this here, I don't have enough reputation to make a simple comment
    – Gendrith
    Dec 9, 2019 at 18:08
  • This code does not work for me for WP v6.1.1 Mar 15, 2023 at 14:46
1

You can also hide this area by placing a small JavaScript code to admin_footer hook.

<?php
add_action('admin_footer', function() {
  global $post_type;
  if ($post_type == 'your_custom_post_type') {
    echo '<script> document.getElementById("edit-slug-box").outerHTML = ""; </script>';
  }
});
0

Well, one quick way would be to just hide the container div using CSS.

add_action('admin_head', 'wpds_custom_admin_post_css');
function wpds_custom_admin_post_css() {

    global $post_type;

    if ($post_type == 'post_type') {
        echo "<style>#edit-slug-box {display:none;}</style>";
    }
}
1
  • that's surely one way to do this. But I was wondering for admin filter or something. But this does work and thank you. Aug 1, 2013 at 18:43
0

I am looking at this filter to achieve something similar:

https://developer.wordpress.org/reference/functions/get_sample_permalink_html/

Returns the HTML of the sample permalink slug editor.

It seems effective. It's available as far as I can tell from WordPress 2.9.0 up.

Sample code:

add_filter('get_sample_permalink_html', 'my_sample_permalink_html', 10, 5);

function my_sample_permalink_html($html, $post_id, $new_title, $new_slug, $post) {
  return '<p>Custom HTML to replace the permalink editor.</p>';
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.