简体   繁体   English

如何从WordPress的自定义帖子类型的URL中删除博客?

[英]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.

相关问题 WordPress自定义帖子类型的URL与博客帖子具有单独的URL - Wordpress custom post-type url have separate url from blog posts 从自定义帖子类型的网址中删除父类别:产品-wordpress - Remove Parent Categories from URL of custom post type: product - wordpress 博客帖子的自定义WordPress帖子类型 - Custom WordPress Post Type for Blog Posts 如何从 wordpress 帖子中删除自定义字段? - How to remove custom fields from wordpress post? 如何使用自定义分类法和自定义帖子类型在 wordpress 中制作短网址? - How to make short url in wordpress with custom taxonomy and custom post type? WordPress使用htaccess从URL更改或删除自定义帖子 - WordPress change or remove custom post slug from url using htaccess 如何删除特定自定义帖子类型的 WordPress 生成的标题标签? - How to remove the WordPress generated title tag for specific custom post type? 如何删除自定义帖子类型管理屏幕中出现的所有Wordpress帖子? - How do I remove all Wordpress Posts from appearing in my Custom Post Type admin screen? 如何从自定义博客中导入wordpress中的标签 - how to import tags in wordpress from custom blog 在Wordpress中隐藏/删除自定义帖子类型选项 - Hide/Remove custom Post Type options in Wordpress
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM