Advertisement
iEmanuele

Custom rewrite URL for CPT

Apr 9th, 2015
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.48 KB | None | 0 0
  1. add_filter( 'post_type_link', '_custom_link' , 10, 2 );
  2. function _custom_link( $post_link, $id = 0 ) {  
  3.     $post = get_post($id);  
  4.     if ( is_wp_error($post) || 'company' != $post->post_type || empty($post->post_name) )  
  5.         return $post_link;  
  6.     return home_url(user_trailingslashit( "$post->post_name" ));  
  7. }
  8. add_action('init', '_custom_rewrite_rule');
  9. function _custom_rewrite_rule() {
  10.     add_rewrite_rule('(.*?)$', 'index.php?company=$matches[1]', 'top');
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement