现在的位置: 首页网络小知识>正文
WordPress页面链接设置为文章ID.html形式
发表于8年前 网络小知识 暂无评论 ⁄ 被围观 5,746 views+

Warning: Use of undefined constant smart_ads_days - assumed 'smart_ads_days' (this will throw an Error in a future version of PHP) in /www/wwwroot/welovelead.net/wp-content/plugins/smart-ads/smartads.php on line 341

WordPress后台有固定链接选项,有很多种页面链接样式。我们可以通过伪原创规则和一些functions代码的改动来实现页面链接形式为“文章ID.html”。

首先,你的网站根目录必须上传相应的伪原创规则(空间上必须支持伪原创),win主机和linux主机的规则不一样,这点大家可以自己去查去找,这里不赘述。

上传完规则后,打开wp后台——外观——编辑——functions.php,把下列代码复制到最后的?>之前并保存。

// 页面链接添加html后缀

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’;

}

}

然后,回到设置——固定链接那里,勾选自定义结构,后面的空白添加“/%post_id%.html”并保存。

这样就实现了页面链接形式为文章ID.html的形式。



给我留言


/ 快捷键:Ctrl+Enter
不想听你唠叨×