Skip to content

Docs: Example for blueprint step writeFile flushes permalink rewrites rules on every page load #2195

Description

@eliot-akira

Making a note of something I noticed in the documentation.

The example for the blueprint step writeFile shows how to create a mu-plugin that enables pretty permalinks.

{
  "step": "writeFile",
  "path": "/wordpress/wp-content/mu-plugins/rewrite.php",
  "data": "<?php /* Use pretty permalinks */ add_action( 'after_setup_theme', function() { global $wp_rewrite; $wp_rewrite->set_permalink_structure('/%postname%/'); $wp_rewrite->flush_rules(); } );"
}

Expanding the code:

<?php
/* Use pretty permalinks */
add_action( 'after_setup_theme', function() {
  global $wp_rewrite;
  $wp_rewrite->set_permalink_structure('/%postname%/');
  $wp_rewrite->flush_rules();
} );

The after_setup_theme action is called on every page load, so it's not the best way to enable pretty permalinks and flush rewrite rules (which is considered an "expensive" operation).

A better way is to do it once using the runPHP step.

{
  "step": "runPHP",
  "code": "<?php include '/var/www/html/wp-load.php'; global $wp_rewrite; $wp_rewrite->set_permalink_structure('/%postname%/'); $wp_rewrite->flush_rules();"
},

There might be a simpler way to achieve it. This PR seems to have made pretty permalinks the default.

update_option('permalink_structure', '/%year%/%monthnum%/%day%/%postname%/');

This method does not flush rewrite rules. Maybe it's not needed because it's always run on a freshly created site.

Anyway, if the default is to use pretty permalinks, then the above mentioned example in the docs is unnecessary and could be removed altogether.

Activity

  1. self-assigned this
    on Jul 16, 2025
  2. added a commit that references this issue on Aug 28, 2026
    3144994
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

[Type] DocumentationImprovements or additions to documentation

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions