I’ve found a way to dynamicaly change the slug field with the short title custom field.
jQuery(document).ready(() => {
const acfField = 'field_61f8bacf53dc5';
const inputShortTitle = document.getElementById('acf-' + acfField);
const slugify = (str) => {
return str.toLowerCase().replace(/ /g, '-')
.replace(/-+/g, '-').replace(/[^\w-]+/g, '');
}
const updateSlug = () => {
wp.data.dispatch('core/editor').editPost({slug: slugify(inputShortTitle.value)});
}
if (inputShortTitle !== null) {
inputShortTitle.addEventListener('input', () => updateSlug());
}
});
wp.data.dispatch('core/editor').editPost({slug: 'my-slug-value-here'});
is the command that can change React Gutenberg slug field component. No more PHP is needed because when I pressed the Save button, the actual value filled by my script is send to the API.
Related Posts:
- How to edit the slug/permalink in Gutenberg?
- Gutenberg Editor: dynamically edit slug field based on ACF field
- Is it possible to get a page link from its slug?
- WordPress slug issue with non-latin characters
- Removing the redirect after changing a page’s slug
- Must slugs be unique?
- How does wordpress keep track of post id when post id is not used in permalinks?
- Stop WordPress from reserving slugs for media items?
- Change slug on post creation
- Prevent WordPress from abbreviating-long-slugs…-in-the-admin
- Post type child of another post type
- How to prevent apostrophes and quotes from appearing in permalinks?
- Why don’t WordPress post slugs allow accents?
- Is It A Good Idea To Change Author Slug (user_nicename field) Directly In MySQL DB?
- How can I force WordPress to redirect to canonical permalinks?
- When creating a WordPress page, a “-2” suffix is added to new pages’ permalinks
- How to i18n slugs for templates?
- Remove parent slug for child pages
- How to Remove Slug From Database?
- How to make draft posts or posts in review accessible via full url / slug?
- Remove parent slug for child pages
- Replace WordPress %postname% suffix with %postid%?
- Limiting the number of words or characters in the slug/permalink
- Make attachment pages require a base url
- How can you receive the most recent permalink or terms of the newly saved post?
- Is using %postname% for permalinks really that bad for performance?
- How to generate random numeric slugs for a custom post type?
- Filter string like a slug
- Change author slug and functionality
- How can I add a page’s ID to its permalink using WP_Rewrite?
- How to modify the slug for the default wp posts without affecting other posttypes?
- Auto-create a pretty permalink for a bunch of posts
- Does rename of page slugs create 301 redirects from old slug to new (same as for posts)?
- Get new WordPress slug from old wordpress slug
- Non latin post slug truncate
- filtering special chars from post slug
- Editing URL character replacement
- Share same Slug for a Custom Post Type and 2 Taxonomies
- force permalink slug for page vs post_type slug parent
- get_permalink returning site home url instead of the url of slug being passed
- wp not making CPT permalink / slugs unique
- Edit page slug after save, cause 404 by linked pages
- Pre-populate Slug / Permalink with URL
- Slugs Disappeared Leaving 404s – Quick way to repopulate?
- Custom permalinks in WordPress
- wordpress how to replace url /bar with foo/bar for custom post type
- Suddenly new posts have the default permalink instead of the post name
- How to Custom Edit Post Title & Permalink Slug?
- Gutenberg output URL to post from attribute with post ID
- how do prevent wordpress from creating permalinks for media files
- I’ve removed my /author/ slug but it clashes with new and existing pages. Any fixes?
- Relative links in Gutenberg
- Bulk append URL (add word to slug)
- add_rewrite_rule – Page Slug from “/foo-bar/” to “/foo/bar/”
- Page content doesn’t display when published but does when previewed as draft?
- Remove international characters from slug – Almost done – Bit help
- How to create posts or pages with the names in wordpress?
- How to remove slug from front page?
- How do I structure my permalinks in WordPress?
- New posts link to old posts (random)
- Modify post slug before saving
- Does wordpress take care of slug collisions?
- assets aren’t loading on a page but loads on others? slug permalink conflict?
- How to prevent wordpress from lowering Capitalized letters
- WordPress slug confusion
- Code snippet to add filter pre_post_link to change Media URL (post_type attachment permalink/slug)
- How do I use the same Tag slug for different Tags?
- home page slug editor missing from WordPress
- How to create a standard WP Page that has the same url as an archive
- permalink not showing correctly using wp_insert_post and post_name
- 404 error on published page with specific permalink
- How to allow different authors to use same post slug?
- Problem with permalinks
- Allowing slash in slug/permalinks
- Author permalink
- Force/Limit the post/page slug to accept only url friendly characters
- Removing or hiding slug/permalink from htaccess
- Automatically remove repeated words in slug
- Uppercase vs. Lowercase page slugs
- Keep wordpress from modifying my permalinks
- Is there a way to remove the option to modify the Slug in post.php
- Possible to hide parts of the slug from get_template_directory_uri and bloginfo(‘template_directory’)
- How to update permalink on the fly?
- How can i edit all posts slug in bulk keeping WP native redirect?
- Display a custom slug in URL depending on user variable
- Post/page without slug
- Different template fallback when changing permalinks
- Error: “Sorry, this content could not be embedded” when using the Embed block
- UI does not show correct Slug after modified using save_post action
- Pages resolve at different URLs (different capitalizations)
- WordPress not remembering old slugs for pages
- Append slug of each blog post with a hash based on a custom field
- Creating WordPress pages with post name as slug
- How to Stop WordPress Change Slug Automatically Same as Title When Publish?
- How to change the category and post prefix/slug to be the same in WordPress?
- Get Page URl when changing slug and permalink
- Can’t Remove Unnecessary Slug
- Changing the URL slug causes redirecting to homepage, or showing 404 or missing lang_code issue
- In the site editor, how can I add a block with a permalink to the post?
- I am getting 500 error when enabling pretty permalinks