0

At the moment my pages are:

domain.com/page

And I want to look them like:

domain.com/example/page
0

I combined this nice solution for adding an additional option to the permalinks page and this snippet for adding a custom base name to page permalinks.

Usage

Save the snippet below as wpse238124-page-base.php, place it in your plugins directory, and activate Page Base on your plugins page. Then, visit your permalinks page, enter your desired page base name e.g. example, and save the changes.

<?php
/*
Plugin Name: Page Base
Plugin URI:
Description: Enables adding a base to page permalinks.
Version: 0.0.1
Author:
Author URI:
License: GPL2/Creative Commons
*/

function wpse238124_page_base_load_permalinks() {
    if ( isset( $_POST['wpse238124_page_base'] ) ) {
        update_option( 'wpse238124_page_base', sanitize_title_with_dashes( $_POST['wpse238124_page_base'] ) );
    }

    // Add a settings field to the permalink page
    add_settings_field( 'wpse238124_page_base', __( 'Page Base' ), 'wpse238124_page_base_field_callback', 'permalink', 'optional' );
}
add_action( 'load-options-permalink.php', 'wpse238124_page_base_load_permalinks' );

function wpse238124_page_base_field_callback() {
    $value = get_option( 'wpse238124_page_base' );  
    echo '<input type="text" value="' . esc_attr( $value ) . '" name="wpse238124_page_base" id="wpse238124_page_base" class="regular-text" />';
}

function wpse238124_page_base_rules() {
    $page_base = get_option( 'wpse238124_page_base' );

    if ( ! $page_base ) {
        return;
    }

    global $wp_rewrite;
    $wp_rewrite->page_structure = $wp_rewrite->root . $page_base . '/%pagename%/'; 
}
add_action( 'init', 'wpse238124_page_base_rules' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.