前端开发入门到精通的在线学习网站

网站首页 > 资源文章 正文

WordPress SEO 另类的伪静态 别名加上.html

qiguaw 2025-01-24 13:35:06 资源文章 64 ℃ 0 评论

大家都知道,在 WordPress 别名 中,加入英文标点时,会都转换为 - ,那么我们在转换完了之后,再加上.html 就没事了

在 functions.php 里加

  1. // 自动为别名添加-html 别名后五位中有-html,则转换成.html

  2. add_filter( 'sanitize_title', 'sanitize_title_with_dot_dashes' );

  3. function sanitize_title_with_dot_dashes( $title, $raw_title = '', $context = 'display' ) {

  4. global $post_type;

  5. if($post_type == 'post'||$post_type == 'bulletin'){ //当文章类型为 文章 或 自定义文章的时候

  6. if (wp_is_post_revision($post_id))

  7. return false;

  8. if(substr($title,-5) !== '.html'){ // 如果别名最后 五位 不是 .html

  9. $title = $title .'.html'; // 则加上.html

  10. }

  11. }

  12. if(substr($title,-5) === '-html'){ // 如果别名 最后五位 是 -html

  13. $title = substr($title,0,-5).'.html'; // 替换 -html 为 .html

  14. }

  15. return $title;

  16. }

将固定链接设置为 /%postname%

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表