-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
75 lines (68 loc) · 1.76 KB
/
functions.php
File metadata and controls
75 lines (68 loc) · 1.76 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
if (!function_exists('mytheme_register_nav_menu')) {
/**
* Register menu
* @link https://developer.wordpress.org/reference/functions/register_nav_menus/
*/
function mytheme_register_nav_menu()
{
register_nav_menus(array(
'primary_menu' => __('Primary Menu', 'larapress'),
'footer_menu' => __('Footer Menu', 'larapress'),
));
}
add_action('after_setup_theme', 'mytheme_register_nav_menu', 0);
}
function get_menu()
{
# Change 'menu' to your own navigation slug.
return wp_get_nav_menu_items('menu');
}
add_action('rest_api_init', function () {
register_rest_route('larapress', '/menu', array(
'methods' => 'GET',
'callback' => 'get_menu',
));
});
/**
* Add custom taxonomy to REST API
* @link https://developer.wordpress.org/reference/functions/register_taxonomy/
*
* @return void
*/
function rest_filter_by_custom_taxonomy($args, $request)
{
if (isset($request['category_slug'])) {
$category_slug = sanitize_text_field($request['category_slug']);
$args['tax_query'] = [
[
'taxonomy' => 'category',
'field' => 'slug',
'terms' => $category_slug,
]
];
} else if (isset($request['tag_slug'])) {
$tag_slug = sanitize_text_field($request['tag_slug']);
$args['tax_query'] = [
[
'taxonomy' => 'post_tag',
'field' => 'slug',
'terms' => $tag_slug,
]
];
}
return $args;
}
add_filter('rest_post_query', 'rest_filter_by_custom_taxonomy', 10, 3);
/**
* Set permalink structure
* @link https://codex.wordpress.org/Function_Reference/set_permalink_structure
*
* @return void
*/
function set_permalink()
{
global $wp_rewrite;
$wp_rewrite->set_permalink_structure('/post/%postname%/');
}
add_action('init', 'set_permalink');