WP_Rewrite::set_category_base() WordPress Method

The WP_Rewrite::set_category_base() method allows you to set the base for your category permalinks. This can be useful if you want to change the way your categories are displayed in your permalinks. For example, if you want your category permalinks to be displayed as /category/cat-name/ instead of the default /?cat=ID, you would use this method to set the category base to /category/.

WP_Rewrite::set_category_base( string $category_base ) #

Sets the category base for the category permalink.


Description

Will update the ‘category_base’ option, if there is a difference between the current category base and the parameter value. Calls WP_Rewrite::init() after the option is updated.


Top ↑

Parameters

$category_base

(string)(Required)Category permalink structure base.


Top ↑

Source

File: wp-includes/class-wp-rewrite.php

	public function set_category_base( $category_base ) {
		if ( get_option( 'category_base' ) !== $category_base ) {
			update_option( 'category_base', $category_base );
			$this->init();
		}
	}


Top ↑

Changelog

Changelog
VersionDescription
1.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.