Skip to content

Instantly share code, notes, and snippets.

@diegoliv
Created March 5, 2015 21:49
Show Gist options
  • Save diegoliv/f6ac6190f0fe33001a96 to your computer and use it in GitHub Desktop.
Save diegoliv/f6ac6190f0fe33001a96 to your computer and use it in GitHub Desktop.
WordPress - Custom permalink structure for pages
// change page permalink structure
add_action( 'init', 'custom_page_rules' );
function custom_page_rules() {
global $wp_rewrite;
$wp_rewrite->page_structure = $wp_rewrite->root . 'my-custom-string/%pagename%';
}
add_filter( 'post_link', 'change_page_links', 1, 3 );
function change_page_links( $post_link, $id=0 ){
$post = get_post($id);
if( is_object($post) && $post->post_type == 'page'){
return home_url('/my-custom-string/'. $post->post_name.'/');
}
return $post_link;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment