[英]How do I remove /blog/ slug in URL in a WordPress custom type post
我在 wordpress 中开发了自定义类型的帖子,并且运行良好。 但是,当您尝试发布文章时,它会显示 /blog/ slug URL example https://example.net/blog/best-construction-company
。 当我尝试在我的代码中删除分类法时,它会删除 slug 但找不到它的显示页面。 此外,当我尝试错误地重写规则时,它仍然显示/blog/slug。 现在,如何删除自定义博客类型上的 /blog/ slug? 即https://example.net/best-construction-company
<?php
function equipments_blog_post_type() {
$labels = array(
'name' => _x( 'Blog Post', 'blog posts and articles' ),
'singular_name' => _x( 'Blog', 'blog posts and articles' ),
'add_new' => _x( 'Add New', 'Blog Post' ),
'add_new_item' => __( 'Add New Blog Post' ),
'edit_item' => __( 'Edit Blog Post' ),
'new_item' => __( 'New Blog Post' ),
'all_items' => __( 'All Blog Posts' ),
'view_item' => __( 'View Blog Post' ),
'search_items' => __( 'Search Blog Posts' ),
'not_found' => __( 'No blog posts found' ),
'not_found_in_trash' => __( 'No blog posts found in the Trash' ),
'menu_name' => 'Blog Post'
);
$args = array(
'labels' => $labels,
'description' => 'Blog posts and articles',
'public' => true,
'menu_position' => 5,
'rewrite' => array('slug' => 'blog'),
'capability_type' => 'post',
'show_in_rest' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'has_archive' => true,
'query_var' => true,
'taxonomies' => array('category', 'post_tag'),
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', 'taxonomies')
);
register_post_type( 'blog', $args );
}
add_action( 'init', 'equipments_blog_post_type' );
function equipments_create_custom_taxonomies(){
register_taxonomy('blog', 'posttypename', array( 'hierarchical' => true, 'label' => 'Blog'));
/* IMPORTANT: This is bad! Don't do this! Read the important update at the top of the page, and update 2 below for details */
flush_rewrite_rules( false );/* Please read "Update 2" before adding this line */
}
add_action('init', 'equipments_create_custom_taxonomies' );
我从来没有尝试过这样做,但是重写的一个常见问题是没有刷新重写规则。 您是否尝试过进入“设置”->“永久链接”并单击“保存”以刷新重写规则?
不过,我仍然怀疑这种方法是否有效——我认为您必须在后台热线 WordPress 以允许您的自定义帖子类型表现得像页面和帖子。
请参阅: https://wordpress.stackexchange.com/questions/203951/remove-slug-from-custom-post-type-post-urls
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.