• At times the requirement may came or the client may want to add an page type extension to the wordpress auto generated page/post url. Mentioned below is the solution to add .html as extension to page or post url (However you can add any type of extension). The solutions worked for me so I expect this may also works for you.

    Changing/Adding an extension to Post’s url.

    Login to your wordpress admin
    Access Settings > Permalinks
    Choose Custom Structure and specify your structure. In my case i had choosed /%postname%.html (The forward slash ‘/’ after postname% been removed and .html had been added)

    Click on save changes. All that it will do is add .html to each and every post url that had been generated by wordpress.

    Changing/Adding an extension to Page’s url.

    Locate rewrite.php . You will found the page in wp-includes folder of your wordpress installation.

    Replace the code from 1131 to 1143 line (locate function get_page_permastruct() function) with the following code

    function get_page_permastruct() {
    		if ( isset($this->page_structure) )
    			return $this->page_structure;
    
    		if (empty($this->permalink_structure)) {
    			$this->page_structure = '';
    			return false;
    		}
    
    		$this->page_structure = $this->root . '%pagename%'. '.html';
    
    		return $this->page_structure;
    	}

    Save the file and upload it. It will appeand an .html to each and every auto-generated url of wordpress page.

    This solution may help you in achieving your goal.

Viewing 1 replies (of 1 total)
  • a pretty bad idea to modify WordPress core files.
    I`m sure there is a hook to jump into the function.

    However I don’t really see the need for that snippet.
    The permalink setup can do exactly that without any modifications?!
    Let me know if I`m missing something.

Viewing 1 replies (of 1 total)
  • The topic ‘How to append an extension type to your page or post url in wordpress’ is closed to new replies.