WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have created a custom post type, but I do not want it to have a permalink. By default, after entering post title, it creates a perma link. I do not them to be generated.

From my reading, it is said that custom post type, will have a permalink and there is no way of disabling it. Is there a way that I can prevent the ajax call that receives the perma link.

share|improve this question
1  
Do you want to hide the permalink under the post title on Edit Post page? Do I understand right? – Max Yudin Mar 15 '13 at 15:02
    
yes, I can hide it with css, but I want to disable it so I dont have to use css. If i could disable the ajax call it would be best – meWantToLearn Mar 15 '13 at 15:12
up vote 5 down vote accepted
<?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;
}
share|improve this answer
    
this didn't work for me - but I had it return '' and it did work. I don't know the implications of that though. – Jacob Raccuia Nov 21 '14 at 22:59
    
Yeah, this doesn't work. – Brett Jan 15 at 2:13
    
That's strange, it worked for me before. Anyway, it has to be changed to meet WP 4.4 requirements. I've updated the code. – Max Yudin Jan 18 at 15:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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