HTML后缀

  • 如何在WordPress文章中添加HTML后缀?

    在WordPress中,要设置文章页的HTML后缀,可以通过编辑主题的functions.php文件或使用插件来实现。一种常见的方法是添加以下代码到functions.php文件中:,,“php,add_filter(‘wp_page_rewrite_rules’, ‘custom_page_rewrite_rules’);,function custom_page_rewrite_rules($rules) {, global $wpdb;, $page_ids = $wpdb˃get_col(“SELECT ID FROM $wpdb˃posts WHERE post_type=’page’ AND post_status=’publish'”);, foreach ($page_ids as $page_id) {, $rules[‘(.+)/([^/]+)\.html$’] = ‘index.php?page_id=’ . $page_id . ‘&name=$matches[1]’;, }, return $rules;,},,add_filter(‘wp_link_target’,’custom_do_page_links’,10,2);,function custom_do_page_links($url, $id) {, $url = str_replace(‘ ‘, ”, get_the_title($id));, $url = strtolower($url);, $url = preg_replace(‘|[^az09]|’, ”, $url);, $url = ‘/’ . $url . ‘.html’;, return array($url, ‘target=”_blank”‘);,},`,,这段代码将使所有页面的URL以.html请确保在修改之前备份您的网站和functions.php`文件。如果您不熟悉代码编辑,建议使用专门的插件来达到相同效果。

    2024-07-31
    026
云产品限时秒杀。精选云产品高防服务器,20M大带宽限量抢购  >>点击进入