문제

In WordPress's PHP library there is a function sanitize_key used to generate database keys and HTML IDs. I'd like to generate a slug from a title that can be used as an HTML ID, from within a Gutenberg block. Is there an equivalent (or close to equivalent) function in the Gutenberg library, or must I make my own?

도움이 되었습니까?

해결책

Use import { cleanForSlug } from "@wordpress/editor"; in your block.js file to import the function in and then use the it like cleanForSlug(stringToClean) to create the ID's.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 wordpress.stackexchange
scroll top