change permalink when title changes

5 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: March 9, 2022   (RSS)

By kitsguru - February 23, 2022 - edited: February 23, 2022

Is there a simple way to detect when the title or another field of a record changes and have the permalink also updated?

I have a custom plugin that adds the category label to the permalink so when either the title or category changes, I want the permalink to update without needing to clear it manually.

Secondly the update permalink table command does not take the category into account. How can I link my plugin to the update table permalink?

Jeff Shields

By kitsguru - March 1, 2022 - edited: March 1, 2022

A hook system in the permalink plugin would be very useful. OR allow 'category:label' in autopopulate_fromFields

Jeff Shields

By kitsguru - March 6, 2022

I have written some custom js to do what I need to do. Here it is for anyone who wants to use it.

# custom.js

$(document).ready(function() {
	$("input[name=title], input[name=name], select[name=category]").on('change', function() {
		// console.log('name or title changed');
		$("input[name=permalink]").val("");
	});
});

I have renamed 'title' to 'name' in some table, and have a 'category' field in most tables. If any of these change then the permalink is cleared and reset on save.

I have a custom plugin to handle the category lookup for label since the permalink does not currently support 'category:label'.

Jeff Shields

By daniel - March 9, 2022

Hey Jeff,

Thanks for posting your update!

Another similar idea would be to use the record_presave hook to check to see if a field has been changed and similarly empty the permalink from the $_REQUEST array. Since the record_presave hook provides the old record's data (new data is in $_REQUEST), it would be relatively simple to compare the new and old values. There's an example included in the Permalinks readme.txt for creating custom permalink formats with a plugin - this should have most of the info required to set this up.

I'll note that we do have "category:label" support in the works for an upcoming release of the Permalinks plugin. Keep an eye out for this! Also, If you have any specific hooks you think would be useful within the plugin, let me know and I can bring them up for consideration.

Thanks,

Daniel
Technical Lead
interactivetools.com