Skip to content

Instantly share code, notes, and snippets.

@akkord87
Created April 19, 2017 18:59
Show Gist options
  • Save akkord87/0e71f324337e5b0bc54dc7e0858b6746 to your computer and use it in GitHub Desktop.
Save akkord87/0e71f324337e5b0bc54dc7e0858b6746 to your computer and use it in GitHub Desktop.
Убрать slug произвольного типа записей из URL WordPress
<?php
//Тип записи services
function true_post_type_rewrite() {
global $wp_rewrite;
// перезаписываем URL
// параметры add_rewrite_tag('%название_тега%', '%маска_символов%', '%url_параметр%')
$wp_rewrite -> add_rewrite_tag("%services%", '([^/]+)', "services=");
$wp_rewrite -> add_permastruct('services', '%services%' );
}
add_action( 'init', 'true_post_type_rewrite');
function true_rewrite_conflicts( $request ) {
if(!is_admin()) {
// перечисляем типы записей с подобной структурой пермалинков
$request['post_type'] = array('services', 'post', 'page', 'blog', 'doctors');
}
return $request;
}
add_filter( 'request', 'true_rewrite_conflicts' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment