sync_category_tag_slugs() WordPress Function

The sync_category_tag_slugs() function is used to synchronize the category and tag slugs. This function is useful when you change the slug of a category or tag, and you want to make sure that the new slug is reflected in the category and tag links.

sync_category_tag_slugs( WP_Term|array $term, string $taxonomy ) #

Synchronizes category and post tag slugs when global terms are enabled.


Parameters

$term

(WP_Term|array)(Required)The term.

$taxonomy

(string)(Required)The taxonomy for $term. Should be 'category' or 'post_tag', as these are the only taxonomies which are processed by this function; anything else will be returned untouched.


Top ↑

Return

(WP_Term|array) Returns $term, after filtering the 'slug' field with sanitize_title() if $taxonomy is 'category' or 'post_tag'.


Top ↑

Source

File: wp-admin/includes/ms.php

function sync_category_tag_slugs( $term, $taxonomy ) {
	if ( global_terms_enabled() && ( 'category' === $taxonomy || 'post_tag' === $taxonomy ) ) {
		if ( is_object( $term ) ) {
			$term->slug = sanitize_title( $term->name );
		} else {
			$term['slug'] = sanitize_title( $term['name'] );
		}
	}
	return $term;
}


Top ↑

Changelog

Changelog
VersionDescription
3.0.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.