I want to remove completely this section under my title in my custom post type. (I don’t need this because I use this only for content management).

enter image description here

With this piece of code I can remove the permalink section:

add_filter('get_sample_permalink_html', 'myfunction', '',4);
function myfunction($return, $id, $new_title, $new_slug) {
    global $post;
    return ($post->post_type == 'mycustomposttype') ? '' : $return;     
}

Now it looks like this but I want to remove the “Get Shortlink” button too.

enter image description here

Is there another filter for doing that?
And yes… with CSS it’s easy but I think a hook would be a better solution 🙂

1 Answer
1

If you filter pre_get_shortlink and return anything but false WordPress will not create a shortlink with its own logic. If your return value is empty, the shortlink UI will not be printed.

Combining both leads us to:

add_filter( 'pre_get_shortlink', '__return_empty_string' );

If you want to restrict the filter to a specific post type, check the second parameter:

add_filter( 'pre_get_shortlink', function( $false, $post_id ) {
    return 'page' === get_post_type( $post_id ) ? '' : $false;
}, 10, 2 );

Leave a Reply

Your email address will not be published. Required fields are marked *