WordPress在自定义帖子URL中添加连字符



我已经在我的WordPress应用程序中创建了一个自定义帖子类型,我希望它的URL通过连字符分隔。例如,自定义帖子的名称是Singh Across The World和 URLsinghacrosstheworld并希望它被singh-across-the-world

我尝试使用singh-across-the-world/singh_across_the_world而不是singhAcrossTheWorld作为第一个参数,但它不起作用。

这是代码,请看一下:

register_post_type("singhAcrossTheWorld", [
"capability_type"   => "post",
"description"       => "Holds our Singh's specific data",
"public"            => true,
"menu_position"     => 6,
"has_archive"       => true,
"show_admin_column" => true,
"supports"          => [
"title",
"editor",
"thumbnail",
"excerpt",
"revisions",
"comments",
"custom-fields",
"page-attributes"
],
"taxonomies"        => [
"post_tag"
],
"labels" => [
"name"               => "Singh across the world",
"singular_name"      => "Singh across the world",
"add_new"            => "Add Singh",
"add_new_item"       => "Add Singh",
"edit_item"          => "Edit Singh",
"new_item"           => "New Singh",
"all_items"          => "All Singhs",
"view_item"          => "View Singh",
"search_items"       => "Search Singhs",
"not_found"          => "No Singhs found",
"not_found_in_trash" => "No Singhs found in the Trash",
"parent_item_colon"  => "",
"menu_name"          => "S. A. T. W."
]
]);

添加此参数rewrite' => array( 'slug' => 'singh-across-the-world' )

register_post_type("singhAcrossTheWorld", [
"capability_type"   => "post",
"description"       => "Holds our Singh's specific data",
"public"            => true,
"menu_position"     => 6,
"has_archive"       => true,
"show_admin_column" => true,
"supports"          => [
"title",
"editor",
"thumbnail",
"excerpt",
"revisions",
"comments",
"custom-fields",
"page-attributes"
],
"taxonomies"        => [
"post_tag"
],
"labels" => [
"name"               => "Singh across the world",
"singular_name"      => "Singh across the world",
"add_new"            => "Add Singh",
"add_new_item"       => "Add Singh",
"edit_item"          => "Edit Singh",
"new_item"           => "New Singh",
"all_items"          => "All Singhs",
"view_item"          => "View Singh",
"search_items"       => "Search Singhs",
"not_found"          => "No Singhs found",
"not_found_in_trash" => "No Singhs found in the Trash",
"parent_item_colon"  => "",
"menu_name"          => "S. A. T. W."
],
'rewrite' => array(
'slug' => 'singh-across-the-world'
)
]);

最新更新