Created
November 6, 2017 19:19
-
-
Save anwerashif/1e3d54990e5bd16bf1cc019c05585ea0 to your computer and use it in GitHub Desktop.
Add .php Extension to WordPress Page Permalinks
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
<?php | |
// Do NOT include the opening PHP tag | |
// Add .PHP to page permalinks | |
add_action('init', 'ss_php_pages', -1); | |
function ss_php_pages() { | |
global $wp_rewrite; | |
if ( !strpos($wp_rewrite->get_page_permastruct(), '.php')){ | |
$wp_rewrite->page_structure = $wp_rewrite->page_structure . '.php'; | |
} | |
$wp_rewrite->flush_rules(); | |
} | |
// Remove slash from page permalinks | |
add_filter('user_trailingslashit', 'no_page_slash_on_ss',66,2); | |
function no_page_slash_on_ss($string, $type){ | |
global $wp_rewrite; | |
if ($wp_rewrite->using_permalinks() && $wp_rewrite->use_trailing_slashes==true && $type == 'page'){ | |
return untrailingslashit($string); | |
}else{ | |
return $string; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment