用代码实现 Page页面 及 Product页面 加 “.html”
1 2 | http://zmingcx.com/wordpress-page-link-html-suffix.html http://zmingcx.com/wordpress-page-tags-url-add-html-suffix.html //加插件的方法 |
1 2 3 | settings > permalinks > Common Settings > Custom Structure > /%postname%.html settings > permalinks > Product permalinks > Custom base > /product/ save change |
[PAGE页面加”.html”]
1 2 | cd /home/wwwroot/default/huajunstone/wp-content/themes/flatsome/ vi functions.php |
1 2 3 4 5 6 7 | add_action('init', 'html_page_permalink', -1); function html_page_permalink() { global $wp_rewrite; if ( !strpos($wp_rewrite->get_page_permastruct(), '.html')){ $wp_rewrite->page_structure = $wp_rewrite->page_structure . '.html'; } } |
1 | systemctl restart nginx.service //重启 |
[Product页面加”.html”]
1 2 | cd /home/wwwroot/default/huajunstone/wp-content/themes/flatsome/ vi functions.php |
1 2 3 4 5 | function wpse_178112_permastruct_html( $post_type, $args ) { if ( $post_type === 'product' ) add_permastruct( $post_type, "{$args->rewrite['slug']}/%$post_type%.html", $args->rewrite ); } add_action( 'registered_post_type', 'wpse_178112_permastruct_html', 10, 2 ); |
1 | systemctl restart nginx.service //重启 |
Esteem 主题 —/%postname%.html
1 | settings > permalinks > Common Settings > Custom Structure > /%postname%.html |
1 2 | cd /home/wwwroot/default/windows-bndstone/wp-content/themes/esteem/ vi functions.php |
1 2 3 4 5 6 7 | add_action('init', 'html_page_permalink', -1); function html_page_permalink() { global $wp_rewrite; if ( !strpos($wp_rewrite->get_page_permastruct(), '.html')){ $wp_rewrite->page_structure = $wp_rewrite->page_structure . '.html'; } } |
1 | systemctl restart nginx.service //重启 |
效果图
Esteem 主题 —/%post_id%.html
1 | settings > permalinks > Common Settings > Custom Structure > /%post_id%.html |
functions.php 不用改动.
效果图