How to remove specific character from wordpress URL

时间:2018-02-15 12:29:56

标签: wordpress

How to remove specific character from wordpress URL as we have installed wordpress in blog folder and using nginx server with PHP 7

Example : www.vkwins.com/blog/press/vinay we need to remove blog from URL it should be: www.vkwins.com/press/vinay

3 个答案:

答案 0 :(得分: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' );

答案 1 :(得分:0)

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

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

答案 2 :(得分:0)

您需要更改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);
    }
}

此外,您必须更改网址重写,以便新网址可以按要求运行

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