从WP作业管理器列表中删除永久链接的公园



我有一个求职网站,它把工作放在以下网址上:

https://www.jarsolutions.co.uk/job/housing-solutions-officer-2/

这是来自插件 WP 作业管理器,我正在尝试简单地删除/job/部分,所以它看起来像这样:

https://www.jarsolutions.co.uk/housing-solutions-officer-2/

问题是,如果我将其从永久链接设置中删除并留空,它会用默认的/jobs/填充它。

我发现这个功能可以让我将其更改为我喜欢的任何内容,但是我找不到如何调整它以完全摆脱它或将其更改为无内容......

function change_job_listing_slug( $args ) {
$args['rewrite']['slug'] = _x( 'careers', 'Job permalink - resave permalinks after changing this', 'job_manager' );
return $args;
}
add_filter( 'register_post_type_job_listing', 'change_job_listing_slug' );

这段代码如果来自他们自己的网站:https://wpjobmanager.com/document/tutorial-changing-the-job-slugpermalink/它还提供了向 url 添加内容的代码片段......但同样,它没有提供有关从 URL 中删除内容的任何信息。

如果有人能指出我正确的方向,那真的会有所帮助。

谢谢:)

从您引用的插件作者的网站上,我确实注意到它说:

注意:从WP作业管理器版本1.27.0开始,作业永久链接可以是 在"设置"->"永久链接"中更改,在"可选"部分下。

对于以前版本的WP作业管理器,请参阅以下指南。谢谢!

这是它列出七个不同代码示例的地方。

在我自己玩这个时,我无法让任何代码示例工作(它们以奇怪的方式中断(。

所以我猜如果你运行的是 1.27.0 以上的版本,那么这些代码示例就不再有效了。

我尝试使用一些重写规则从 url 中删除/job,但问题是,有关插件的所有内容都在寻找一个关键字(默认:job(,它将通过该关键字搜索内容。

如果它被删除,WordPress将期望URL必须是页面。可以删除它,但它需要大量的努力。

最好的办法是向WP作业管理器提交支持票,并希望他们将其放在路线图上,或者付钱给像我这样的插件开发人员来编写必要的代码来让您做到这一点。

以下是从术语 URL 中删除自定义分类 slug(«job»(的方法:

这是代码的主要部分,您可以将其插入到当前的主题函数中.php,只是不要忘记将每个函数中的分类名称/蛞蝓更改为您自己的值。

add_filter('request', 'rudr_change_term_request', 1, 1 );
function rudr_change_term_request($query){
$tax_name = 'product_cat'; // specify you taxonomy name here, it can be also 'category' or 'post_tag'
// Request for child terms differs, we should make an additional check
if( $query['attachment'] ) :
$include_children = true;
$name = $query['attachment'];
else:
$include_children = false;
$name = $query['name'];
endif;

$term = get_term_by('slug', $name, $tax_name); // get the current term to make sure it exists
if (isset($name) && $term && !is_wp_error($term)): // check it here
if( $include_children ) {
unset($query['attachment']);
$parent = $term->parent;
while( $parent ) {
$parent_term = get_term( $parent, $tax_name);
$name = $parent_term->slug . '/' . $name;
$parent = $parent_term->parent;
}
} else {
unset($query['name']);
}
switch( $tax_name ):
case 'category':{
$query['category_name'] = $name; // for categories
break;
}
case 'post_tag':{
$query['tag'] = $name; // for post tags
break;
}
default:{
$query[$tax_name] = $name; // for another taxonomies
break;
}
endswitch;
endif;
return $query;
}

add_filter( 'term_link', 'rudr_term_permalink', 10, 3 );
function rudr_term_permalink( $url, $term, $taxonomy ){
$taxonomy_name = 'product_cat'; // your taxonomy name here
$taxonomy_slug = 'product_cat'; // the taxonomy slug can be different with the taxonomy name (like 'post_tag' and 'tag' )
// exit the function if taxonomy slug is not in URL
if ( strpos($url, $taxonomy_slug) === FALSE || $taxonomy != $taxonomy_name ) return $url;
$url = str_replace('/' . $taxonomy_slug, '', $url);
return $url;
}

并且不要忘记来自旧URL的301重定向,这是您的网站SEO所必需的。

add_action('template_redirect', 'rudr_old_term_redirect');
function rudr_old_term_redirect() {
$taxonomy_name = 'product_cat';
$taxonomy_slug = 'product_cat';
// exit the redirect function if taxonomy slug is not in URL
if( strpos( $_SERVER['REQUEST_URI'], $taxonomy_slug ) === FALSE)
return;
if( ( is_category() && $taxonomy_name=='category' ) || ( is_tag() && $taxonomy_name=='post_tag' ) || is_tax( $taxonomy_name ) ) :
wp_redirect( site_url( str_replace($taxonomy_slug, '', $_SERVER['REQUEST_URI']) ), 301 );
exit();
endif;
}

该代码使用不同的分层和非分层分类法进行了测试,并在此永久链接设置中运行良好。

为了从URL中删除"job/",您必须按照以下步骤操作

第 1 步:将永久链接设置更改为"帖子名称" 第 2 步:将作业创建为"帖子">

如果您不想在 Post 中创建,则无法从 URL 中删除"job/",除非您在 URL(https://www.jarsolutions.co.uk/job-housing-solutions-officer-2/( 中添加"job-

"作为前缀

要删除作业 slug 或永久链接,如果您使用的是 WordPress 或 WP 作业管理器的任何服务,您可以使用"删除 CPT"插件。我在我的网站上使用了它,现在你可以看到额外的基础或类别基础已经消失 https://mappians.com/hardrockhotelsmaldives 这是我的裸 URL 示例,它看起来很棒,没有任何基础。

最新更新