WP_Rewrite::set_permalink_structure() WordPress Method

The WP_Rewrite::set_permalink_structure() method sets the permalink structure for the site. This method takes a string as its only parameter. The string should be the desired permalink structure for the site. The structure should include the leading slash, but should not include any trailing slash. For example, to set the permalink structure to "/%year%/%monthnum%/%day%/%postname%/", you would use the following code: $wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' ); This method should be called before the 'init' action is fired.

WP_Rewrite::set_permalink_structure( string $permalink_structure ) #

Sets the main permalink structure for the site.


Description

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

Fires the ‘permalink_structure_changed’ action once the init call has processed passing the old and new values


Top ↑

Parameters

$permalink_structure

(string)(Required)Permalink structure.


Top ↑

Source

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

	public function set_permalink_structure( $permalink_structure ) {
		if ( $permalink_structure != $this->permalink_structure ) {
			$old_permalink_structure = $this->permalink_structure;
			update_option( 'permalink_structure', $permalink_structure );

			$this->init();

			/**
			 * Fires after the permalink structure is updated.
			 *
			 * @since 2.8.0
			 *
			 * @param string $old_permalink_structure The previous permalink structure.
			 * @param string $permalink_structure     The new permalink structure.
			 */
			do_action( 'permalink_structure_changed', $old_permalink_structure, $permalink_structure );
		}
	}


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.