Mr.Singh
Mr.Singh

Reputation: 1791

WordPress adding hyphen in custom post url

I have created a custom post type in my WordPress application and I want its URL to be separated via Hyphens. For example, The name of the custom post is Singh Across The World and in URL singhacrosstheworld and want it to be singh-across-the-world.

I tried using singh-across-the-world / singh_across_the_world instead of singhAcrossTheWorld as the first parameter, but it did not work.

Here is the code, please have a look:

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."
    ]
]);

Upvotes: 0

Views: 839

Answers (1)

Vel
Vel

Reputation: 9341

add this args 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'
    )
]);

Upvotes: 1

Related Questions