[英]how to remove blog from custom post type url in wordpress?
The custom post type URL is created using toolset plugin. 使用工具集插件创建自定义帖子类型URL。 We have post named faq.
我们有一个名为常见问题的帖子。 for example: the link should be www.example.com/faq but the link in my side is www.example.com/blog/faq I tried to fix it using rewrite condition in function.php
例如:链接应该是www.example.com/faq,但是我这边的链接是www.example.com/blog/faq我试图使用function.php中的重写条件来修复它
'rewrite'=>array('with_front'=> false,'slug'=>'blog');
Try this method to remove blog in your URL 尝试使用此方法删除URL中的博客
<?php
function custom_post_request( $query ) {
if ( ! $query->is_main_query() )
return;
if ( 2 != count( $query->query ) || ! isset( $query->query['page'] ) ) {
return;
}
if ( ! empty( $query->query['name'] ) ) {
$query->set( 'post_type', array( 'blog') );
}
}
add_action( 'pre_get_posts', 'custom_post_request' );
function remove_custom_slug( $post_link, $post, $leavename ) {
if ( 'blog' != $post->post_type || 'blog' != $post->post_status ) {
return $post_link;
}
$post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
return $post_link;
}
add_filter( 'post_type_link', 'remove_custom_slug', 10, 3 );
?>
You just need to remove blog and put '/' in rewrite rule of custom post type of FAQ. 您只需要删除博客并将“ /”置于FAQ的自定义帖子类型的重写规则中即可。
'rewrite'=>array('with_front'=> false,'slug'=>'/');
Let me know does it working or not? 让我知道它是否有效?
Adding 'rewrite'=>array('with_front'=> false,'slug'=>'/'); 添加'rewrite'=> array('with_front'=> false,'slug'=>'/');
works for the CTP but breaks the regular blog PT 适用于CTP,但会破坏常规博客PT
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.