How can i remove or replace question mark from url using wordpress?

I’m showing child categories data in custom page using wordpress. Problem is that i’m fetching those child categories from parent category slug.

www.example.com/custom/?cp=category-slug

Read More

I want to remove ?cp= and make it like thiss www.example.com/custom/category-slug.

Is there any way to rewrite this specific custom page url, i will appreciate if someone help me regarding this.

Related posts

Leave a Reply

2 comments

  1. Instead of this, you can create a custom category template to list all of its sub-category data. Refer this https://codex.wordpress.org/Category_Templates Its url would be http://www.example.com/custom-post-type-slug/category-slug Also it won’t affect other category pages.

    Step-1: Create a category template:

    In your themes folder, create a .php file as save as category-slug.php

    Step-2: Add a loop to list all its subcategory data

    Just copy and paste the below code:

       <?php
            $cat_name=get_category($cat);
            $cat_id=$cat_name->cat_ID;
            $categories = get_categories("child_of=".$cat_id);
    
            foreach ($categories as $cat) { ?>
    
                <div class="subcategory">
                    <?php query_posts("cat=$cat->cat_ID&showposts=-1&order=ASC&orderby=name"); ?>
                            <h4 ><?php single_cat_title(); ?></h4>
                            <hr>
                            <ul>
                            <?php while (have_posts()) : the_post();
    
                                ?>
                                <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
                                    </li>
                            <?php endwhile; ?>
                 </div>
            <?php }?>
    

    Change that loop according to your needs.