Possible to add new token %parent_title% ?
-
A while ago I realised that
post_name
in WordPress never changes after a post is created. For instance, updating a post’s title does not updatepost_name
.
On my site, I needed to have child posts to have a permalink like /parent_name/child_name and started using the%parent_postname%
token. However, when I changed the title of a parent and regenerated the permalink for a child, the parent_name part would not update.I resolved this issue (been testing this for over 6 months) by creating a new %parent_title% token, which simply uses post titles instead of post names.
Would you consider adding this to the plugin? Please find the code below (it was duplicated from %parent_postname%):
// Replace %parent_title% with the respective post title with the // parent post title if parent post is selected if ( false !== strpos( $replace_tag, "%parent_title%" ) ) { $parents = get_ancestors( $post_id, $post->post_type, 'post_type' ); $posttitles = ''; if ( $parents && is_array( $parents ) && ! empty( $parents ) && count( $parents ) >= 1 ) { $parent = get_post( $parents[0] ); $posttitles = sanitize_title( $parent->post_title ) . '/'; } $title = sanitize_title( $post->post_title ); $posttitles .= $title; $replace_tag = str_replace( '%parent_title%', $posttitles, $replace_tag ); }
Many thanks,
Luca
- The topic ‘Possible to add new token %parent_title% ?’ is closed to new replies.