-
-
Save sayal322l/169d7de41647b65c7e902d2bbd89db00 to your computer and use it in GitHub Desktop.
PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<php | |
function register_custom_post_type() { | |
register_post_type('slug-name', array( | |
'label' => 'ブログ', | |
'public' => true, | |
'show_in_rest' => true, // REST API を有効化 | |
'supports' => array('title', 'editor', 'thumbnail'), | |
)); | |
} | |
add_action('init', 'register_custom_post_type'); | |
?> | |
<php | |
function add_thumbnail_to_rest_api($data, $post, $context) { | |
if (has_post_thumbnail($post->ID)) { | |
$data->data['thumbnail'] = get_the_post_thumbnail_url($post->ID, 'full'); | |
} else { | |
$data->data['thumbnail'] = get_template_directory_uri() . '/img-path'; | |
} | |
return $data; | |
} | |
add_filter('rest_prepare_post', 'add_thumbnail_to_rest_api', 10, 3); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment