-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfunctions.php
More file actions
35 lines (30 loc) · 865 Bytes
/
functions.php
File metadata and controls
35 lines (30 loc) · 865 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
/**
* Load styles and scripts.
*/
require get_template_directory() . '/inc/scripts.php';
// Enable featured images.
add_theme_support( 'post-thumbnails' );
// Add a featured image size.
add_image_size( 'featured_image', 960, 400, array( 'center', 'center' ) );
add_image_size( 'post_thumb', 640, 427, array( 'center', 'center' ) );
add_action( 'rest_api_init', 'epf_insert_thumbnail_url' );
function epf_insert_thumbnail_url() {
register_rest_field( 'post',
'thumbnail',
array(
'get_callback' => 'epf_get_thumbnail_url',
'update_callback' => null,
'schema' => null,
)
);
}
function epf_get_thumbnail_url( $post ){
if(has_post_thumbnail( $post['id']) ){
$imgArray = wp_get_attachment_image_src( get_post_thumbnail_id( $post['id'] ), 'post_thumb' );
$imgURL = $imgArray[0];
return $imgURL;
} else {
return false;
}
}