Gist a8b13a2c8fa9122cb5cfd663f61f15ba
✓ Published0🌍 Public
KKopylovVitalik
Last edited Jun 19, 2020
Created on Jun 19, 2020
This example demonstrates a WordPress plugin that automatically limits a post slug to three words by cutting it at the third hyphen during post saving. The code hooks into the `save_post` action and uses the functions `get_post_field`, `wp_update_post`, and `wp_is_post_revision` to modify the post name. The slug’s text is split into an array with `explode`, and the first three segments are recombined and assigned via the `post_name` field. The action is temporarily removed and re-added to prevent an infinite loop during the update.
AI-generated description