Skip Navigation

[Gelöst] custom title – update slug

This support ticket is created vor 5 Jahren, 9 Monaten. 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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

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)

Dieses Thema enthält 2 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Akhil vor 5 Jahren, 9 Monaten.

Assistiert von: Waqar.

Author
Artikel
#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!