0
以下代碼允許我刪除我的主域郵件的父類別。 我的問題是,我使用第三方插件爲了映射我的作者名稱中的第二個域。Wordpress刪除URL中的父類別(域映射)
- domain1.com 主域
- domain2.com MAPPED DOMAIN
永久鏈接結構:
- domain1.com/me/cat/subcat/postname = > domain2.com/cat/subcat/postname
所以基本上,domain1.com/me映射到domain2.com,它的工作好這樣
,但如果我刪除貓蛞蝓和只讓SUBCAT像這樣(用腳本):
- domain1.com/me/subcat/postname WORKING
- domain2.com/subcat/postname NOT WORKING(ERR_TOO_MANY_REDIRECTS)
腳本刪除父塞在URL
add_filter('post_link', 'remove_parent_category', 10, 3);
function remove_parent_category($permalink, $post, $leavename)
{
$cats = get_the_category($post->ID);
if ($cats) {
usort($cats, '_usort_terms_by_ID');
$category = $cats[0]->slug;
if ($parent = $cats[0]->parent) {
// Find parent categories and replace them in the link
$parentcats = get_category_parents($parent, false, '/', true);
$permalink = str_replace($parentcats, '', $permalink);
}
}
return $permalink;
}