|
|
Custom Post Link
Started by: fahimS-2
in: Toolset Professional Support
Quick solution available
Problem:
How to remove the base slug of a custom post type?
Solution:
It is not recommended to do that as slugs need to be unique in WordPress.
You can do it by adding the custom code below:
function na_remove_slug( $post_link, $post, $leavename ) {
if ( 'events' != $post->post_type || 'publish' != $post->post_status ) {
return $post_link;
}
$post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
return $post_link;
}
function na_parse_request( $query ) {
if ( ! $query->is_main_query() || 2 != count( $query->query ) || ! isset( $query->query['page'] ) ) {
return;
}
if ( ! empty( $query->query['name'] ) ) {
$query->set( 'post_type', array( 'post', 'events', 'page' ) );
}
}
add_action( 'pre_get_posts', 'na_parse_request' );
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/
|
|
2 |
5 |
3 years, 1 month ago
fahimS-2
|