theme development - How to change parent permalink?

admin2025-01-07  4

I have a theme with hardcoded permalink structure for some posts. Those posts open with

site/parent/page

structure.

I created a filter that replaces the link from "site/parent/page" to "site/newparent/page" in functions.php with:

add_action('init', 'change_slug_of_post_type_parent', 20);
function change_slug_of_post_type_parent()
{   
$args = get_post_type_object("parent");
$args->rewrite["slug"] = "newparent";
register_post_type($args->name, $args);
}

Links are now generated OK, but when I click on them, the page doesn't load.

Can someone please help? I am sure this is easy fix, but I cant get around it. I am new to wordpress programming (I used GSCMS, and CMSGS before).

Thanks

I have a theme with hardcoded permalink structure for some posts. Those posts open with

site.com/parent/page

structure.

I created a filter that replaces the link from "site.com/parent/page" to "site.com/newparent/page" in functions.php with:

add_action('init', 'change_slug_of_post_type_parent', 20);
function change_slug_of_post_type_parent()
{   
$args = get_post_type_object("parent");
$args->rewrite["slug"] = "newparent";
register_post_type($args->name, $args);
}

Links are now generated OK, but when I click on them, the page doesn't load.

Can someone please help? I am sure this is easy fix, but I cant get around it. I am new to wordpress programming (I used GSCMS, and CMSGS before).

Thanks

Share Improve this question asked Oct 19, 2016 at 11:33 mrmutmrmut 1033 bronze badges 4
  • Did you flush rewrite rules ? – Benoti Commented Oct 19, 2016 at 11:40
  • Is /parent a page with the slug parent? – Tom J Nowell Commented Oct 19, 2016 at 11:50
  • Benoti - thank you, I feel like an idiot. It worked instantly after flushing. Will you please make an answer, so I can award solution point? Thanks! .-) – mrmut Commented Oct 19, 2016 at 14:15
  • 1 Tom J Nowell - No, the page is not parent, it is just a category pointer. – mrmut Commented Oct 19, 2016 at 14:16
Add a comment  | 

1 Answer 1

Reset to default 0

Benoti posted the solution in comments: "Did you flush rewrite rules?"

How to flush: https://www.webhostinghero.com/3-ways-to-flush-the-rewrite-cache-in-wordpress/

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736253683a144.html

最新回复(0)