• I’m using categories and tags to organize my main menu on the Canard theme.
    However, in the URL I’m unable to get rid of the words “category” or “tag”.
    For example, “Travel” is a menu item based on post categories.
    The URL is https://www.theindiaedition.com/category/travel/
    In addition, on clicking to navigate to “Travel” on the menu, there is text generated “Category: Travel” before showing the posts on the page.
    I would like to remove the auto-generated text “Category: Travel” and make the URL https://www.theindiaedition.com/travel/
    and so on, for all my menu items based on post categories and tags.
    I tried updating the custom structure for categories and tags on the Permalinks Page to “/” or “.” but neither worked.
    Any help would be much appreciated, thank you.

Viewing 9 replies - 1 through 9 (of 9 total)
  • I found plugins for you.

    Hi @drd29,

    I tried updating the custom structure for categories and tags on the Permalinks Page to “/” or “.” but neither worked.

    If you navigate to Settings > Permalinks in your admin area, you can replace “category” by entering a new value into the Category base field, but there isn’t a way to completely remove the value from your URL.

    You could have a search through the plugin directory, as @webkong suggested, to see if there’s a plugin that will completely remove “category.”

    In addition, on clicking to navigate to “Travel” on the menu, there is text generated “Category: Travel” before showing the posts on the page.

    That extra text can be removed by making edits to the theme’s HTML/PHP via a child theme.

    If you’re comfortable playing about with your theme’s code, then you can good introductions and steps to set up a child theme here:

    After you have created your child theme, navigate to the parent theme’s inc/template-tags.php file and scroll down to the the_archive_title() function:

    function the_archive_title( $before = '', $after = '' ) {
    	if ( is_category() ) {
    		$title = sprintf( __( 'Category: %s', 'canard' ), single_cat_title( '', false ) );
    	} elseif ( is_tag() ) {
    		$title = sprintf( __( 'Tag: %s', 'canard' ), single_tag_title( '', false ) );
    	} elseif ( is_author() ) {
    		$title = sprintf( __( 'Author: %s', 'canard' ), '<span class="vcard">' . get_the_author() . '</span>' );
    	} elseif ( is_year() ) {
    		$title = sprintf( __( 'Year: %s', 'canard' ), get_the_date( _x( 'Y', 'yearly archives date format', 'canard' ) ) );
    	} elseif ( is_month() ) {
    		$title = sprintf( __( 'Month: %s', 'canard' ), get_the_date( _x( 'F Y', 'monthly archives date format', 'canard' ) ) );
    	} elseif ( is_day() ) {
    		$title = sprintf( __( 'Day: %s', 'canard' ), get_the_date( _x( 'F j, Y', 'daily archives date format', 'canard' ) ) );
    	} elseif ( is_tax( 'post_format' ) ) {
    		if ( is_tax( 'post_format', 'post-format-aside' ) ) {
    			$title = _x( 'Asides', 'post format archive title', 'canard' );
    		} elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) {
    			$title = _x( 'Galleries', 'post format archive title', 'canard' );
    		} elseif ( is_tax( 'post_format', 'post-format-image' ) ) {
    			$title = _x( 'Images', 'post format archive title', 'canard' );
    		} elseif ( is_tax( 'post_format', 'post-format-video' ) ) {
    			$title = _x( 'Videos', 'post format archive title', 'canard' );
    		} elseif ( is_tax( 'post_format', 'post-format-quote' ) ) {
    			$title = _x( 'Quotes', 'post format archive title', 'canard' );
    		} elseif ( is_tax( 'post_format', 'post-format-link' ) ) {
    			$title = _x( 'Links', 'post format archive title', 'canard' );
    		} elseif ( is_tax( 'post_format', 'post-format-status' ) ) {
    			$title = _x( 'Statuses', 'post format archive title', 'canard' );
    		} elseif ( is_tax( 'post_format', 'post-format-audio' ) ) {
    			$title = _x( 'Audio', 'post format archive title', 'canard' );
    		} elseif ( is_tax( 'post_format', 'post-format-chat' ) ) {
    			$title = _x( 'Chats', 'post format archive title', 'canard' );
    		}
    	} elseif ( is_post_type_archive() ) {
    		$title = sprintf( __( 'Archives: %s', 'canard' ), post_type_archive_title( '', false ) );
    	} elseif ( is_tax() ) {
    		$tax = get_taxonomy( get_queried_object()->taxonomy );
    		/* translators: 1: Taxonomy singular name, 2: Current taxonomy term */
    		$title = sprintf( __( '%1$s: %2$s', 'canard' ), $tax->labels->singular_name, single_term_title( '', false ) );
    	} else {
    		$title = __( 'Archives', 'canard' );
    	}
    
    	/**
    	 * Filter the archive title.
    	 *
    	 * @param string $title Archive title to be displayed.
    	 */
    	$title = apply_filters( 'get_the_archive_title', $title );
    
    	if ( ! empty( $title ) ) {
    		echo $before . $title . $after;
    	}
    }

    The above function is what’s define the different ways titles are displayed on various archive pages, including your category pages.

    Copy/paste the function in its entirety to your child theme’s functions.php file.

    Next, navigate to this specific part of the function in your child theme’s file:

    if ( is_category() ) {
    	$title = sprintf( __( 'Category: %s', 'canard' ), single_cat_title( '', false ) );

    We need to remove Category: there in order to remove it from your site’s category pages:

    if ( is_category() ) {
    	$title = sprintf( __( '%s', 'canard' ), single_cat_title( '', false ) );

    Let me know how you get on with those steps! We’re right here to help out if any questions come up while you’re going through them.

    Thread Starter drd29

    (@drd29)

    Thank you, webkong and Siobhan!
    I set up the child theme and followed the notes above and from the link you sent (https://codex.www.ads-software.com/Child_Themes), but I seem to have done something wrong because I caused my site to go down when I uploaded the child theme. I had named the child theme folder “canard-child”. I’m not sure what I’ve missed?
    I also included the enqueuing for rtl.css – was I supposed to skip that?
    Appreciate your help, as always. Thank you.

    This is the style.css I used:

    /*
    Theme Name:   Canard Child
    Theme URI:    https://www.theindiaedition.com/canard-child/
    Description:  Canard child theme
    Author:       DRD
    Author URI:   https://www.theindiaedition.com
    Template:     canard
    Version:      1.0.0
    Text Domain:  canard-child
    */

    And this is my functions.php file:

    <?php
    add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
    function my_theme_enqueue_styles() {
        wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    
    add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
    function my_theme_enqueue_styles() {
        wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/rtl.css' );
    
    if ( ! function_exists( 'the_archive_title' ) ) :
    /**
     * Shim for <code>the_archive_title()</code>.
     *
     * Display the archive title based on the queried object.
     *
     * @todo Remove this function when WordPress 4.3 is released.
     *
     * @param string $before Optional. Content to prepend to the title. Default empty.
     * @param string $after  Optional. Content to append to the title. Default empty.
     */
    function the_archive_title( $before = '', $after = '' ) {
    	if ( is_category() ) {
    		$title = sprintf( __( '%s', 'canard' ), single_cat_title( '', false ) );
    	} elseif ( is_tag() ) {
    		$title = sprintf( __( '%s', 'canard' ), single_tag_title( '', false ) );
    	} elseif ( is_author() ) {
    		$title = sprintf( __( 'Author: %s', 'canard' ), '<span class="vcard">' . get_the_author() . '</span>' );
    	} elseif ( is_year() ) {
    		$title = sprintf( __( 'Year: %s', 'canard' ), get_the_date( _x( 'Y', 'yearly archives date format', 'canard' ) ) );
    	} elseif ( is_month() ) {
    		$title = sprintf( __( 'Month: %s', 'canard' ), get_the_date( _x( 'F Y', 'monthly archives date format', 'canard' ) ) );
    	} elseif ( is_day() ) {
    		$title = sprintf( __( 'Day: %s', 'canard' ), get_the_date( _x( 'F j, Y', 'daily archives date format', 'canard' ) ) );
    	} elseif ( is_tax( 'post_format' ) ) {
    		if ( is_tax( 'post_format', 'post-format-aside' ) ) {
    			$title = _x( 'Asides', 'post format archive title', 'canard' );
    		} elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) {
    			$title = _x( 'Galleries', 'post format archive title', 'canard' );
    		} elseif ( is_tax( 'post_format', 'post-format-image' ) ) {
    			$title = _x( 'Images', 'post format archive title', 'canard' );
    		} elseif ( is_tax( 'post_format', 'post-format-video' ) ) {
    			$title = _x( 'Videos', 'post format archive title', 'canard' );
    		} elseif ( is_tax( 'post_format', 'post-format-quote' ) ) {
    			$title = _x( 'Quotes', 'post format archive title', 'canard' );
    		} elseif ( is_tax( 'post_format', 'post-format-link' ) ) {
    			$title = _x( 'Links', 'post format archive title', 'canard' );
    		} elseif ( is_tax( 'post_format', 'post-format-status' ) ) {
    			$title = _x( 'Statuses', 'post format archive title', 'canard' );
    		} elseif ( is_tax( 'post_format', 'post-format-audio' ) ) {
    			$title = _x( 'Audio', 'post format archive title', 'canard' );
    		} elseif ( is_tax( 'post_format', 'post-format-chat' ) ) {
    			$title = _x( 'Chats', 'post format archive title', 'canard' );
    		}
    	} elseif ( is_post_type_archive() ) {
    		$title = sprintf( __( 'Archives: %s', 'canard' ), post_type_archive_title( '', false ) );
    	} elseif ( is_tax() ) {
    		$tax = get_taxonomy( get_queried_object()->taxonomy );
    		/* translators: 1: Taxonomy singular name, 2: Current taxonomy term */
    		$title = sprintf( __( '%1$s: %2$s', 'canard' ), $tax->labels->singular_name, single_term_title( '', false ) );
    	} else {
    		$title = __( 'Archives', 'canard' );
    	}
    
    	/**
    	 * Filter the archive title.
    	 *
    	 * @param string $title Archive title to be displayed.
    	 */
    	$title = apply_filters( 'get_the_archive_title', $title );
    
    	if ( ! empty( $title ) ) {
    		echo $before . $title . $after;
    	}
    }
    endif;
    
    }
    ?>
    Moderator Kathryn Presner

    (@zoonini)

    Hi there – couple of things I noticed:

    I also included the enqueuing for rtl.css – was I supposed to skip that?

    Unless your site uses a right-to-left language (like Arabic, for example) you do not need to enqueue the RTL stylesheet.

    You should not include a closing PHP tag in the functions.php file, so remove this at the bottom:
    ?>

    Also try removing the entire archive title function and just keep the child-theme enqueuing function and see if that works first.

    Moderator Kathryn Presner

    (@zoonini)

    p.s. the reason your site went down is likely because you tried to add two functions with the same name: my_theme_enqueue_styles()

    WordPress kind of flips out when that happens and doesn’t know what to do. ??

    Thread Starter drd29

    (@drd29)

    Hi Kathryn, thanks for your help! I’ve updated the style sheet and functions.php. The child theme in itself seems to be working, but my original issue of removing the “Category:” and “Tag:” text hasn’t been resolved. Any idea where I’m going wrong?

    Here’s what I have for my functions.php now:

    <?php
    add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
    function my_theme_enqueue_styles() {
        wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    
    if ( ! function_exists( 'the_archive_title' ) ) :
    /**
     * Shim for <code>the_archive_title()</code>.
     *
     * Display the archive title based on the queried object.
     *
     * @todo Remove this function when WordPress 4.3 is released.
     *
     * @param string $before Optional. Content to prepend to the title. Default empty.
     * @param string $after  Optional. Content to append to the title. Default empty.
     */
    function the_archive_title( $before = '', $after = '' ) {
    	if ( is_category() ) {
    		$title = sprintf( __( '%s', 'canard' ), single_cat_title( '', false ) );
    	} elseif ( is_tag() ) {
    		$title = sprintf( __( '%s', 'canard' ), single_tag_title( '', false ) );
    	} elseif ( is_author() ) {
    		$title = sprintf( __( 'Author: %s', 'canard' ), '<span class="vcard">' . get_the_author() . '</span>' );
    	} elseif ( is_year() ) {
    		$title = sprintf( __( 'Year: %s', 'canard' ), get_the_date( _x( 'Y', 'yearly archives date format', 'canard' ) ) );
    	} elseif ( is_month() ) {
    		$title = sprintf( __( 'Month: %s', 'canard' ), get_the_date( _x( 'F Y', 'monthly archives date format', 'canard' ) ) );
    	} elseif ( is_day() ) {
    		$title = sprintf( __( 'Day: %s', 'canard' ), get_the_date( _x( 'F j, Y', 'daily archives date format', 'canard' ) ) );
    	} elseif ( is_tax( 'post_format' ) ) {
    		if ( is_tax( 'post_format', 'post-format-aside' ) ) {
    			$title = _x( 'Asides', 'post format archive title', 'canard' );
    		} elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) {
    			$title = _x( 'Galleries', 'post format archive title', 'canard' );
    		} elseif ( is_tax( 'post_format', 'post-format-image' ) ) {
    			$title = _x( 'Images', 'post format archive title', 'canard' );
    		} elseif ( is_tax( 'post_format', 'post-format-video' ) ) {
    			$title = _x( 'Videos', 'post format archive title', 'canard' );
    		} elseif ( is_tax( 'post_format', 'post-format-quote' ) ) {
    			$title = _x( 'Quotes', 'post format archive title', 'canard' );
    		} elseif ( is_tax( 'post_format', 'post-format-link' ) ) {
    			$title = _x( 'Links', 'post format archive title', 'canard' );
    		} elseif ( is_tax( 'post_format', 'post-format-status' ) ) {
    			$title = _x( 'Statuses', 'post format archive title', 'canard' );
    		} elseif ( is_tax( 'post_format', 'post-format-audio' ) ) {
    			$title = _x( 'Audio', 'post format archive title', 'canard' );
    		} elseif ( is_tax( 'post_format', 'post-format-chat' ) ) {
    			$title = _x( 'Chats', 'post format archive title', 'canard' );
    		}
    	} elseif ( is_post_type_archive() ) {
    		$title = sprintf( __( 'Archives: %s', 'canard' ), post_type_archive_title( '', false ) );
    	} elseif ( is_tax() ) {
    		$tax = get_taxonomy( get_queried_object()->taxonomy );
    		/* translators: 1: Taxonomy singular name, 2: Current taxonomy term */
    		$title = sprintf( __( '%1$s: %2$s', 'canard' ), $tax->labels->singular_name, single_term_title( '', false ) );
    	} else {
    		$title = __( 'Archives', 'canard' );
    	}
    
    	/**
    	 * Filter the archive title.
    	 *
    	 * @param string $title Archive title to be displayed.
    	 */
    	$title = apply_filters( 'get_the_archive_title', $title );
    
    	if ( ! empty( $title ) ) {
    		echo $before . $title . $after;
    	}
    }
    endif;
    
    }
    Moderator Kathryn Presner

    (@zoonini)

    The child theme in itself seems to be working

    Great, glad that’s set up now.

    Let’s look again at what you are trying to do, since you mentioned a couple of different things.

    Removing Category Base from URL

    To remove the “category” portion of the URL, the simplest way to do that is using a plugin designed to accomplish that, as webkong suggested above. URL structure is not part of the theme, but is in WordPress core. The best way to alter that is outside of the theme, and a plugin would be a good route. There are a number of different ones you could try out at the search link provided above:

    https://www.ads-software.com/plugins/search.php?type=term&q=remove+category

    Try selecting one of those plugins and see how it goes. If you need help using a specific plugin, you can then post in its specific support forum.

    In addition, on clicking to navigate to “Travel” on the menu, there is text generated “Category: Travel” before showing the posts on the page.

    There are two options here, depending on your goal.

    1) Do you want to remove the entire page heading on Category and Tag pages? For example, do you want to get rid of “Category: Travel” entirel? If so, this can be done with custom CSS alone.

    .category .page-title, .tag .page-title {
      display: none;
    }

    You can add that to your child theme’s style.css file.

    2) Or are you instead trying to remove only the specific word “Category:” or “Tag:” and leave visible the name of the category itself, like “Travel”?

    Thread Starter drd29

    (@drd29)

    Ideally I would prefer

    2) Or are you instead trying to remove only the specific word "Category:" or "Tag:" and leave visible the name of the category itself, like "Travel"?

    For now I’ve added the code you mentioned and that’s half my problem solved, thank you so much Kathryn for taking the time to help me!

    Moderator Kathryn Presner

    (@zoonini)

    To remove just the words “Category” and “Tag” but leave the actual category/tag name, try adding this function in your child theme’s functions.php file:

    https://wordpress.stackexchange.com/a/179590

    You’d need to then remove the custom CSS you added to see if it’s working. I just tested it and it seems to work well on my Canard child theme.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Removing Category Base from URL and Auto generated text from page’ is closed to new replies.