How to Add .php Extension to WordPress Page Permalinks

How to Add .php Extension to WordPress Page Permalinks

wprocket

Here is the code snippets add it to your theme’s functions.php.

<?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;
      }
}

 

GenesisPro728x90

Facebook
Twitter
LinkedIn
Pinterest
Tumblr
Anwer Ashif

Anwer Ashif

Founder of RainaStudio. Help businesses and individuals to create and outstand their online presence. Our success rate is measurable. Our blog served all around the world and counting.

Leave a Reply

Your email address will not be published. Required fields are marked *