最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is there an equivalent of the PHP function sanitize_key in Gutenberg?

programmeradmin2浏览0评论

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?

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?

Share Improve this question asked Oct 13, 2019 at 9:35 SeanSean 6677 silver badges17 bronze badges 1
  • The function cleanForSlug in Gutenberg's url.js seems to do the job. However I'm not sure if this is available to import into a Gutenberg block. – Sean Commented Mar 19, 2020 at 22:15
Add a comment  | 

1 Answer 1

Reset to default 1

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.

发布评论

评论列表(0)

  1. 暂无评论