php - 使用 Gutenberg 将缩略图添加到自定义帖子类型 WordPress

标签 php wordpress custom-post-type wordpress-gutenberg

我在 WordPress 中创建了一个自定义帖子类型,我想添加对缩略图的支持。我已经创建了指定支持缩略图的帖子类型,但在帖子类型页面的编辑窗口中没有出现指定缩略图的选项。

我用的是Gutenberg作为编辑器,用经典编辑器,没有问题。有什么解决办法吗?

谢谢!

最佳答案

首先在functions.php中添加theme_support

  add_theme_support( 'post-thumbnails', array( 'custom_post_type_name' )

然后将“编辑器”和“缩略图”添加到支持中,并确保已将 show_in_rest 设置为 true。

  'supports' => array( 'editor', 'thumbnail'),
  'show_in_rest' => true,

否则它在古腾堡中将不起作用。以下是支持文档:

https://codex.wordpress.org/Function_Reference/post_type_supports

关于php - 使用 Gutenberg 将缩略图添加到自定义帖子类型 WordPress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52988957/

相关文章:

php - 当我的 URL 末尾有撇号时,为什么我会收到 SQL 错误?

php - Laravel 中如何访问数组

PHP preg_match 错误

php - 在激活 Hook 中注册简码不起作用

php - WordPress 中的自动保存和自定义字段

WordPress自定义帖子类型类别链接

php - CodeIgniter ionic 授权 : How is is_admin() working?

wordpress - gtmetrix 站点问题 : remove the query string and encode the parameters into the URL

php - 在 echo 中使用 Wordpress 方法 - 似乎无法正常工作?

php - 根据当前查询变量在 Wordpress 中预过滤 get_next_post()