0

My theme uses the following code:

'rewrite' => array('slug' => $this->safe_name . '-detail'),

which produces this slug:

http://www.example.com/estate-detail/4-bedroom-property-for-sale/

I need to get rid of the 'estate-detail' part so I changed the rule to just:

'rewrite' => array('slug' => ' '),

This produces the slug as:

http://www.example.com//4-bedroom-property-for-sale/

How do I get rid of the double forward slash?

0
add_filter( 'post_type_link', 'filterslash_post_type_link', 11, 2);

function filterslash_post_type_link( $post_link, $post ){
    $post_link = home_url("/$post->post_name/");
    return $post_link;
}
9
  • will this work only for custom post types? Pages and normal posts do not require any editing.
    – JoaMika
    Dec 10 '13 at 23:07
  • to make it work with builtin post - add_filter( 'post_link', 'filterslash_post_type_link', 11, 2); to make it work with builtin page - add_filter( 'page_link', 'filterslash_post_type_link', 11, 2);
    – Shazzad
    Dec 10 '13 at 23:10
  • i also added this to my themes functions.php but it doesn't seem to work... The links still contain the //
    – JoaMika
    Dec 10 '13 at 23:10
  • i am using custom post types - not normal posts...
    – JoaMika
    Dec 10 '13 at 23:10
  • try using a higher priority. Try Changing 11 to 9999.
    – Shazzad
    Dec 10 '13 at 23:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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