Title: wp_install_maybe_enable_pretty_permalinks
Published: April 23, 2015
Last modified: May 20, 2026

---

# wp_install_maybe_enable_pretty_permalinks(): bool

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/wp_install_maybe_enable_pretty_permalinks/?output_format=md#description)
 * [Return](https://developer.wordpress.org/reference/functions/wp_install_maybe_enable_pretty_permalinks/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_install_maybe_enable_pretty_permalinks/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_install_maybe_enable_pretty_permalinks/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_install_maybe_enable_pretty_permalinks/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_install_maybe_enable_pretty_permalinks/?output_format=md#wp--skip-link--target)

Maybe enable pretty permalinks on installation.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/wp_install_maybe_enable_pretty_permalinks/?output_format=md#description)󠁿

If after enabling pretty permalinks don’t work, fallback to query-string permalinks.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_install_maybe_enable_pretty_permalinks/?output_format=md#return)󠁿

 bool Whether pretty permalinks are enabled. False otherwise.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_install_maybe_enable_pretty_permalinks/?output_format=md#source)󠁿

    ```php
    function wp_install_maybe_enable_pretty_permalinks() {
    	global $wp_rewrite;

    	// Bail if a permalink structure is already enabled.
    	if ( get_option( 'permalink_structure' ) ) {
    		return true;
    	}

    	/*
    	 * The Permalink structures to attempt.
    	 *
    	 * The first is designed for mod_rewrite or nginx rewriting.
    	 *
    	 * The second is PATHINFO-based permalinks for web server configurations
    	 * without a true rewrite module enabled.
    	 */
    	$permalink_structures = array(
    		'/%year%/%monthnum%/%day%/%postname%/',
    		'/index.php/%year%/%monthnum%/%day%/%postname%/',
    	);

    	foreach ( (array) $permalink_structures as $permalink_structure ) {
    		$wp_rewrite->set_permalink_structure( $permalink_structure );

    		/*
    		 * Flush rules with the hard option to force refresh of the web-server's
    		 * rewrite config file (e.g. .htaccess or web.config).
    		 */
    		$wp_rewrite->flush_rules( true );

    		$test_url = '';

    		// Test against a real WordPress post.
    		$first_post = get_page_by_path( sanitize_title( _x( 'hello-world', 'Default post slug' ) ), OBJECT, 'post' );
    		if ( $first_post ) {
    			$test_url = get_permalink( $first_post->ID );
    		}

    		/*
    		 * Send a request to the site, and check whether
    		 * the 'X-Pingback' header is returned as expected.
    		 *
    		 * Uses wp_remote_get() instead of wp_remote_head() because web servers
    		 * can block head requests.
    		 */
    		$response          = wp_remote_get( $test_url, array( 'timeout' => 5 ) );
    		$x_pingback_header = wp_remote_retrieve_header( $response, 'X-Pingback' );
    		$pretty_permalinks = $x_pingback_header && get_bloginfo( 'pingback_url' ) === $x_pingback_header;

    		if ( $pretty_permalinks ) {
    			return true;
    		}
    	}

    	/*
    	 * If it makes it this far, pretty permalinks failed.
    	 * Fallback to query-string permalinks.
    	 */
    	$wp_rewrite->set_permalink_structure( '' );
    	$wp_rewrite->flush_rules( true );

    	return false;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/upgrade.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-admin/includes/upgrade.php#L496)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-admin/includes/upgrade.php#L496-L558)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_install_maybe_enable_pretty_permalinks/?output_format=md#related)󠁿

| Uses | Description | 
| [sanitize_title()](https://developer.wordpress.org/reference/functions/sanitize_title/)`wp-includes/formatting.php` |

Sanitizes a string into a slug, which can be used in URLs or HTML attributes.

  | 
| [wp_remote_get()](https://developer.wordpress.org/reference/functions/wp_remote_get/)`wp-includes/http.php` |

Performs an HTTP request using the GET method and returns its response.

  | 
| [wp_remote_retrieve_header()](https://developer.wordpress.org/reference/functions/wp_remote_retrieve_header/)`wp-includes/http.php` |

Retrieves a single header by name from the raw response.

  | 
| [get_page_by_path()](https://developer.wordpress.org/reference/functions/get_page_by_path/)`wp-includes/post.php` |

Retrieves a page given its path.

  | 
| [WP_Rewrite::set_permalink_structure()](https://developer.wordpress.org/reference/classes/wp_rewrite/set_permalink_structure/)`wp-includes/class-wp-rewrite.php` |

Sets the main permalink structure for the site.

  | 
| [WP_Rewrite::flush_rules()](https://developer.wordpress.org/reference/classes/wp_rewrite/flush_rules/)`wp-includes/class-wp-rewrite.php` |

Removes rewrite rules and then recreate rewrite rules.

  | 
| [_x()](https://developer.wordpress.org/reference/functions/_x/)`wp-includes/l10n.php` |

Retrieves translated string with gettext context.

  | 
| [get_bloginfo()](https://developer.wordpress.org/reference/functions/get_bloginfo/)`wp-includes/general-template.php` |

Retrieves information about the current site.

  | 
| [get_permalink()](https://developer.wordpress.org/reference/functions/get_permalink/)`wp-includes/link-template.php` |

Retrieves the full permalink for the current post or post ID.

  | 
| [get_option()](https://developer.wordpress.org/reference/functions/get_option/)`wp-includes/option.php` |

Retrieves an option value based on an option name.

  |

[Show 5 more](https://developer.wordpress.org/reference/functions/wp_install_maybe_enable_pretty_permalinks/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_install_maybe_enable_pretty_permalinks/?output_format=md#)

| Used by | Description | 
| [wp_install()](https://developer.wordpress.org/reference/functions/wp_install/)`wp-admin/includes/upgrade.php` |

Installs the site.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_install_maybe_enable_pretty_permalinks/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.2.0](https://developer.wordpress.org/reference/since/4.2.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fblue-sea-697d.quartiers047.workers.dev%3A443%2Fhttps%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_install_maybe_enable_pretty_permalinks%2F)
before being able to contribute a note or feedback.