Community Forums › Forums › Archived Forums › Design Tips and Tricks › Adding shtml extension to blog pages
Tagged: blog home page, extension, php
- This topic has 1 reply, 1 voice, and was last updated 8 years, 11 months ago by
unklee.
-
AuthorPosts
-
March 20, 2016 at 8:14 pm #181950
unklee
MemberSince I have been converting my HTML site to a WP blog using the Minimum Pro theme, I have asked about a dozen questions on this forum and most of them have been answered very helpfully, thanks. So I'm going to try once more please.
Because I had about a hundred self-coded HTML pages, all with the extension .shtml, I would like to be able to give them the same URL when they are made into WordPress pages - to keep all the internal and external links. I can easily make the filename the same by editing the name WP chooses, but adding the extension is a little trickier.
There are several plugins to do this, but I only found one that worked - Add Any Extension to Pages by Marios Alexandrou. It adds the extension to pages but not to posts, as I want, but with one minor issue. It doesn't add the extension to the static home page, but it does add it to the blog home page, which I'd prefer not to have (to keep it the way it was before). Marios has been extremely helpful in correcting some of my mistakes, but he hasn't yet been able to find a way to stop this.
I looked for coding solutions, and again found only one that worked - this code by Carlo Fontanos works if you ignore the permalink change (which adds the extension to posts, which I don't want) and just insert the code for pages into the functions.php file. But again, the blog home page gets the extension added.
I can overcome this little change in URL using a 301 Redirect in the .htaccess file, but it would be nice to get the blog home page not to add the extension. Does anybody have any ideas please? I'm wondering if there's some way to except the blog home page, but I don't know how to do that. Here's Carlo's code:
add_action('init', 'html_page_permalink', -1); register_activation_hook(__FILE__, 'cvf_active'); register_deactivation_hook(__FILE__, 'cvf_deactive'); function html_page_permalink() { global $wp_rewrite; if ( !strpos($wp_rewrite->get_page_permastruct(), '.html')){ $wp_rewrite->page_structure = $wp_rewrite->page_structure . '.html'; } } add_filter('user_trailingslashit', 'no_page_slash',66,2); function no_page_slash($string, $type){ global $wp_rewrite; if ($wp_rewrite->using_permalinks() && $wp_rewrite->use_trailing_slashes==true && $type == 'page'){ return untrailingslashit($string); } else { return $string; } } function cvf_active() { global $wp_rewrite; if ( !strpos($wp_rewrite->get_page_permastruct(), '.html')){ $wp_rewrite->page_structure = $wp_rewrite->page_structure . '.html'; } $wp_rewrite->flush_rules(); } function cvf_deactive() { global $wp_rewrite; $wp_rewrite->page_structure = str_replace(".html","",$wp_rewrite->page_structure); $wp_rewrite->flush_rules(); }
April 6, 2016 at 5:03 am #183035unklee
MemberFor the record, I decided not to add the extension and put up with the redirects for a while.
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.