-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
158 lines (132 loc) · 4.99 KB
/
functions.php
File metadata and controls
158 lines (132 loc) · 4.99 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
/**
* Nx Wordpress functions and definitions.
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package WordPress
* @subpackage Nx Wordpress
* @since Nx Wordpress 0.1.0
*/
// Exit if accessed directly.
defined('ABSPATH') || exit;
// load composer dependencies.
require_once __DIR__ . '/vendor/autoload.php';
// Disable Gutenberg on the back end.
add_filter( 'use_block_editor_for_post', '__return_false' );
// Disable Gutenberg for widgets.
add_filter( 'use_widgets_block_editor', '__return_false' );
/** Scan Directory Function */
function nx_scandir($path) {
/** Array Directory Files */
$files = [];
/** Scan Directory Folder */
$scandir = array_diff(scandir($path), ['.', '..']);
foreach ($scandir as $file):
$dir = is_dir("{$path}{$file}") ? nx_scandir("{$path}{$file}/") : ["{$path}{$file}"];
$files = [...$files, ...$dir];
endforeach;
return $files;
}
// Custom additions.
foreach (nx_scandir(get_template_directory()."/inc/") as $file):
require_once $file;
endforeach;
// Add style and script files
add_action('wp_enqueue_scripts', function () {
// swiper style and script
wp_enqueue_script('swiper', 'https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.js', ver: '11.2.6');
wp_enqueue_style('swiper', 'https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.css', ver: '11.2.6');
// theme style and script
wp_enqueue_style('nx-wordpress', get_template_directory_uri() . '/dist/style.css', ['swiper'], filemtime(get_template_directory() . '/dist/style.css'), 'all');
wp_enqueue_script('nx-wordpress', get_template_directory_uri() . '/dist/script.js', ['swiper'], filemtime(get_template_directory() . '/dist/script.js'), true);
});
// Enable menus setting
register_nav_menus([
'primary-menu' => 'Primary Menu',
'mobile-menu' => 'Mobile Menu',
]);
// Enable featured image
add_theme_support('post-thumbnails');
// Enable custom header logo
// add_theme_support('custom-header');
// Enable sidebar widget
// register_sidebar([
// 'name' => 'Sidebar Widget',
// 'id' => 'sidebar-widget'
// ]);
// Enable excerpt or short description
add_post_type_support('page', 'excerpt');
// Create custom post type
add_action("init", fn() => register_post_type(
'news',
[
'label' => 'News',
'labels' => [
'name' => _x('News', 'post general name'),
'singular_name' => _x('News', 'post singular name'),
'search_items' => 'Search News',
'all_items' => 'All News',
'edit_item' => 'Edit News',
'update_item' => 'Update News',
'add_new_item' => 'Add News',
],
'public' => true,
// 'hierarchical' => true, // it is use to convert page type
'exclude_from_search' => true,
'publicly_queryable' => true,
'show_ui' => true,
'rewrite' => ['with_front' => false],
'menu_position' => 5,
'menu_icon' => 'dashicons-media-document',
'taxonomies' => ['post_tag', 'category'],
'supports' => ['title', 'editor', 'thumbnail', 'excerpt', 'page-attributes'],
'has_archive' => true,
])
);
// Create custom taxonomy type
add_action(
"init",
fn() => register_taxonomy(
'author',
'news',
[
'label' => 'Authors',
'labels' => [
'name' => _x('Authors', 'taxonomy general name'),
'singular_name' => _x('Author', 'taxonomy singular name'),
'search_items' => 'Search Author',
'all_items' => 'All Authors',
'parent_item' => 'Parent Author',
'edit_item' => 'Edit Author',
'update_item' => 'Update Author',
'add_new_item' => 'Add New Author',
],
'hierarchical' => true, // it is use to convert categories type
'rewrite' => ['with_front' => false],
'has_archive' => true,
]
)
);
// Create custom field
add_action('add_meta_boxes', fn() => add_meta_box('meta_header_script', 'Custom Header Script', 'Head_script', 'news'));
function Head_script($post) {
$HeadScript = get_post_meta($post->ID, 'HeadScript', true);
echo '<textarea name="header_script" style="width:100%; height:125px;">' . $HeadScript . '</textarea>';
};
add_action('save_post', function ($post_ID) {
if (isset($_POST['header_script'])) {
update_post_meta($post_ID, 'HeadScript', esc_html($_POST['header_script']));
}
});
// apply filter for title
add_filter('the_title', fn($content) => ucwords($content));
// add custom title
add_filter('wp_title', fn($title) => $title ? "{$title} | " . get_bloginfo() : get_bloginfo('description'));
// Form Submit Button
add_action('wp_footer', function () {
echo "
<script type='text/javascript'>
const gf_submit = () => document.querySelector('.gform_footer input[type=submit]')?.click();
</script>";
});