Created
March 5, 2015 21:49
-
-
Save diegoliv/f6ac6190f0fe33001a96 to your computer and use it in GitHub Desktop.
WordPress - Custom permalink structure for pages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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