How to Add .PHP Extension at the End of the WordPress Post URL

add php extension to wordpress permalinks
<?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;
      }
}

Leave a Reply