Wordpress - Disable permalink on custom post type

<?php
    add_filter('get_sample_permalink_html', 'my_hide_permalinks');
    function my_hide_permalinks($in){
        global $post;
        if($post->post_type == 'my_post_type')
            $out = preg_replace('~<div id="edit-slug-box".*</div>~Ui', '', $in);
        return $out;
    }

This will remove:

  • Permalink itself
  • View Post button
  • Get Shortlink button

If you want to remove permalink only, replace the line containing preg_replace with

$out = preg_replace('~<span id="sample-permalink".*</span>~Ui', '', $in);

UPDATE:

get_sample_permalink_html has changed in version 4.4.

Here is the updated and tested code:

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

function my_hide_permalinks($return, $post_id, $new_title, $new_slug, $post)
{
    if($post->post_type == 'my_post_type') {
        return '';
    }
    return $return;
}

While the accepted answer seems to only hide the permalink from showing, but still being generated and accessible, you can disable the permalink from showing and being accessible by setting certain register_post_types parameters.

I've achieved what I needed by only setting the following, but depending on your specific case, you may want to adjust some of the other parameters.

'public' => false,
'show_ui' => true

More: https://wordpress.stackexchange.com/a/108658/33056