在URL中重写单词-WordPress



我正在使用WordPress并购买了主题。主题生成URL http://martin.heskovci.sk/avalon_td_gallery/zvierata/我想将其更改为http://martin.heskovci.sk/portfolio/portfolio/portfolio/zvierata/zvierata/

我在.htacces and functions.php中尝试了一些东西,但没有结果。我在代码中找到了一些东西

<a href="'.$avalon_td_post_permalink.'" class="avalon_td_btn"><span>'.esc_html__('View Full Gallery', 'avalon').'</span> <i class="xcon-right-open-big"></i></a>

我认为我必须重写"。$ avalon_td_post_permalink"。但是我不知道怎么做。有人帮我吗?

更新1

我找到了这个。我必须在哪里重写" avalon_td_gallery"?我尝试更改重写行和最后一行,但是在创建一个新的画廊之后,我将仍然获得404。

// Arguments for gallery projects
            $args = array(
                'labels'                => $labels,
                'public'                => true,
                'publicly_queryable'    => true,
                'show_in_nav_menus'     => true,
                'show_in_admin_bar'     => true,
                'exclude_from_search'   => false,
                'show_ui'               => true,
                'show_in_menu'          => true,
                'menu_position'         => 4,
                'menu_icon'             => 'dashicons-format-gallery', //XXS_PLUGIN_URI . 'assets/img/portfolio-icon.png',
                'can_export'            => true,
                'delete_with_user'      => false,
                'hierarchical'          => false,
                'has_archive'           => true,
                'capability_type'       => 'post',
                'rewrite'               => array( 'slug' => 'avalon_td_gallery', 'with_front' => false ),
                'supports'              => array( 'title', 'editor', 'thumbnail' )
            );
            // Register our gallery post type
            register_post_type( 'avalon_td_gallery', $args );

更新2:

'rewrite' => array( 'slug' => 'avalon_td_gallery', 'with_front' => false ),

到这个

'rewrite' => array( 'slug' => 'portfolio', 'with_front' => false ),

和重要的事情,设置 ->永久链接页面并点击保存。这将冲洗重写规则,现在其工作!

我无法发表评论 - 所以我会在这里回复。

我将首先搜索包含 avalon_td_gallery 的文件。

取决于主题如何生成URL - 这将决定如何更改URL。如果是使用自定义帖子类型制成的,则只需更改重写规则即可。 avalon_td_gallery 将在register_post_type函数内部。并且要么更改值,要么在此功能中添加重写规则:

'rewrite' => array('slug' => 'portfolio'),

显然,您应该确保使用此重写规则没有冲突。

创建自定义重写规则" WordPress Way"的另一种方法是add_rewrite_rule函数。如果在此内找到 avalon_td_gallery ,只需更改重写规则的第一个参数,然后在Wordress中更新固定链接即可。例如:

add_rewrite_rule( 'avalon_td_gallery/([^/]+)', 'index.php?gallery_item=$matches[1]', 'top' );

希望会有所帮助。

update

因此,您不应该在所有文件中更改Avalon_td_gallery的所有实例。您仍然希望处理程序或查询变量保留为avalon_td_gallery,您只希望URL更改。这是register_post_type函数的非常简单的EXAMPE。

function codex_custom_init() {
    $args = array(
        'public' => true,
        'label'  => 'Gallery',
        'rewrite' => array( 'slug' => 'portfolio' )
    );
    register_post_type( 'avalon_td_gallery', $args );
}
add_action( 'init', 'codex_custom_init' );

因此,只有lug会改变。如果将register_post_type处理程序更改为其他内容,它将认为它是新的帖子类型。所以不要这样做

register_post_type( 'portfolio', $args ); // -< THIS IS WRONG

如果您可以恢复帖子类型的注册,请返回到 avalon_td_gallery gallery,这将使您的数据在该命名空间下保持,但只会更改URL。

最新更新