Skip Navigation

[Resolved] custom title – update slug

This support ticket is created 5 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by Akhil 5 years, 10 months ago.

Assisted by: Waqar.

Author
Posts
#1185774

Hi Waqar, still working on the custom title. all look good now,. except the slug is not updated when i click the 'update' button.

i understand this code will re-create the slug, but it doesn't for my case.

$slug = sanitize_title($title);

Do you see any issue ?

i insert it right after ..

.....
$data['post_title'] = $title ;
$slug = sanitize_title($title);
//Updates the post title to your new title.
}
return $data;

#1186010

Hi Dee,

Thanks for asking! I'd be happy to help.

The "sanitize_title" prepares the string to be used as part of the URL ( ref: https://codex.wordpress.org/Function_Reference/sanitize_title ) but doesn't actually saves it as a slug.

You'll need to tell your function to use the sanitized title value as a "post_name" (slug) and your code will become:


.....
// update the title
$data['post_title'] = $title ;

// update the slug (same as the title, but sanitized)
$data['post_name'] =  sanitize_title($title) ;

}
return $data;

I hope this helps!

regards,
Waqar

#1188217

My issue is resolved now. Thank you!