Monday, July 22, 2019

how to remove category from slug

//function to remove slug

function trek_remove_cpt_slug( $post_link, $post, $leavename ) {

if ( 'activity' != $post->post_type&&
'hiking' != $post->post_type&&
'activity' != $post->post_type&&
'peak' != $post->post_type&&
'tour' != $post->post_type &&
'nepaltrekking' != $post->post_type ||
'publish' != $post->post_status ) {
return $post_link;
}

$post_link = str_replace( '/'. $post->post_type . '/', '/', $post_link );

return $post_link;
}
add_filter( 'post_type_link', 'trek_remove_cpt_slug', 10, 3 );

function trek_parse_request_trick( $query ) {

// Only noop the main query
if ( ! $query->is_main_query() )
return;

// Only noop our very specific rewrite rule match
if ( 2 != count( $query->query ) || ! isset( $query->query['page'] ) ) {
return;
}

// ‘name’ will be set if post permalinks are just post_name, otherwise the page rule will match
if ( ! empty( $query->query['name'] ) ) {
$query->set( 'post_type', array( 'post', 'page', 'nepaltrekking' ,'blog','tour','peak','hiking','activity' ) );
}
}
add_action( 'pre_get_posts', 'trek_parse_request_trick' );

No comments:

Featured Post

Make money online

https://www.wpbeginner.com/beginners-guide/make-money-online/?fbclid=IwAR0_9_5aHmbB4rDisaPevdnO4uAgo0N9heHgPu1TjerjurE5ilD2NyzeB2A

Popular Posts