【问题标题】:How to remove specific character from wordpress URL如何从 wordpress URL 中删除特定字符
【发布时间】:2018-07-26 05:09:30
【问题描述】:

当我们在博客文件夹中安装 wordpress 并使用 PHP 7 的 nginx 服务器时,如何从 wordpress URL 中删除特定字符

示例:www.vkwins.com/blog/press/vinay 我们需要从 URL 中删除博客,它应该是:www.vkwins.com/press/vinay

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    如果你想删除你的帖子类型,那么你可以使用这个代码..

    使用您的帖子类型更改帖子类型服务并将其粘贴到functions.php

    function na_remove_slug( $post_link, $post, $leavename ) {
    
        if ( 'service' != $post->post_type || 'publish' != $post->post_status ) {
            return $post_link;
        }
    
        $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
    
        return $post_link;
    }
    add_filter( 'post_type_link', 'na_remove_slug', 10, 3 );
    
    /*====================================================
    remove of code of custom post type...
    ======================================================*/
    
    function na_parse_request( $query ) {
    
        if ( ! $query->is_main_query() || 2 != count( $query->query ) || ! isset( $query->query['page'] ) ) {
            return;
        }
    
        if ( ! empty( $query->query['name'] ) ) {
            $query->set( 'post_type', array( 'post', 'service', 'page' ) );
        }
    }
    add_action( 'pre_get_posts', 'na_parse_request' );
    

    【讨论】:

      【解决方案2】:

      你需要改变 wp-includes/link-template.php

      在函数get_permalink中

      if ($post->post_type == 'page') return get_page_link($post, $leavename, $sample);
      elseif ( $post->post_type == 'attachment' )
          return get_attachment_link( $post, $leavename );
      elseif (in_array($post->post_type, get_post_types(array('_builtin' => false)))) {
          if ($post->post_type == 'press') {
              return str_replace('/blog', '', get_post_permalink($post, $leavename, $sample));
          } else {
              return get_post_permalink($post, $leavename, $sample);
          }
      }
      

      另外,您必须对 url 重写进行更改,以便新的 url 可以根据需要工作

      location /press {
          root   /html/www/;
          try_files $uri $uri/ /blog/index.php?$args ;
      }
      

      【讨论】:

        【解决方案3】:

        通常通过在 .htaccess 文件中添加 url 重写规则来完成 URL 重写。 Wordpress 有一个内置的功能名称 Permalink 来做到这一点。

        在 Wordpress 管理员中,转到设置 → 永久链接面板(选项 → WordPress 2.5 之前的永久链接),您可以选择一种“常见”结构,或者使用结构标签在“自定义结构”字段中输入您自己的结构标签来定义您的选择的网址。 或者你可以试试this

        【讨论】:

        • 然后你可以试试 Wp 管理面板永久链接
        • wp admin 永久链接如果不在 ngnix.conf 文件中添加位置就无法工作
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-11-20
        • 1970-01-01
        • 1970-01-01
        • 2016-10-25
        • 1970-01-01
        相关资源
        最近更新 更多