|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* DesignFly functions and definitions |
|
4
|
|
|
* |
|
5
|
|
|
* @link https://developer.wordpress.org/themes/basics/theme-functions/ |
|
6
|
|
|
* |
|
7
|
|
|
* @package DesignFly |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
if ( ! function_exists( 'designfly_setup' ) ) : |
|
11
|
|
|
/** |
|
12
|
|
|
* Sets up theme defaults and registers support for various WordPress features. |
|
13
|
|
|
* |
|
14
|
|
|
* Note that this function is hooked into the after_setup_theme hook, which |
|
15
|
|
|
* runs before the init hook. The init hook is too late for some features, such |
|
16
|
|
|
* as indicating support for post thumbnails. |
|
17
|
|
|
*/ |
|
18
|
|
|
function designfly_setup() { |
|
19
|
|
|
/* |
|
20
|
|
|
* Make theme available for translation. |
|
21
|
|
|
* Translations can be filed in the /languages/ directory. |
|
22
|
|
|
* If you're building a theme based on DesignFly, use a find and replace |
|
23
|
|
|
* to change 'designfly' to the name of your theme in all the template files. |
|
24
|
|
|
*/ |
|
25
|
|
|
load_theme_textdomain( 'designfly', get_template_directory() . '/languages' ); |
|
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
// Add default posts and comments RSS feed links to head. |
|
28
|
|
|
add_theme_support( 'automatic-feed-links' ); |
|
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
/* |
|
31
|
|
|
* Let WordPress manage the document title. |
|
32
|
|
|
* By adding theme support, we declare that this theme does not use a |
|
33
|
|
|
* hard-coded <title> tag in the document head, and expect WordPress to |
|
34
|
|
|
* provide it for us. |
|
35
|
|
|
*/ |
|
36
|
|
|
add_theme_support( 'title-tag' ); |
|
37
|
|
|
|
|
38
|
|
|
/* |
|
39
|
|
|
* Enable support for Post Thumbnails on posts and pages. |
|
40
|
|
|
* |
|
41
|
|
|
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/ |
|
42
|
|
|
*/ |
|
43
|
|
|
add_theme_support( 'post-thumbnails' ); |
|
44
|
|
|
|
|
45
|
|
|
// This theme uses wp_nav_menu() in one location. |
|
46
|
|
|
register_nav_menus( array( |
|
|
|
|
|
|
47
|
|
|
'menu-1' => esc_html__( 'Primary', 'designfly' ), |
|
|
|
|
|
|
48
|
|
|
) ); |
|
49
|
|
|
|
|
50
|
|
|
/* |
|
51
|
|
|
* Switch default core markup for search form, comment form, and comments |
|
52
|
|
|
* to output valid HTML5. |
|
53
|
|
|
*/ |
|
54
|
|
|
add_theme_support( 'html5', array( |
|
55
|
|
|
'search-form', |
|
56
|
|
|
'comment-form', |
|
57
|
|
|
'comment-list', |
|
58
|
|
|
'gallery', |
|
59
|
|
|
'caption', |
|
60
|
|
|
) ); |
|
61
|
|
|
|
|
62
|
|
|
// Add theme support for selective refresh for widgets. |
|
63
|
|
|
add_theme_support( 'customize-selective-refresh-widgets' ); |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Add support for core custom logo. |
|
67
|
|
|
* |
|
68
|
|
|
* @link https://codex.wordpress.org/Theme_Logo |
|
69
|
|
|
*/ |
|
70
|
|
|
add_theme_support( 'custom-logo', array( |
|
71
|
|
|
'height' => 65, |
|
72
|
|
|
'width' => 250, |
|
73
|
|
|
'flex-width' => true, |
|
74
|
|
|
'flex-height' => false, |
|
75
|
|
|
) ); |
|
76
|
|
|
} |
|
77
|
|
|
endif; |
|
78
|
|
|
add_action( 'after_setup_theme', 'designfly_setup' ); |
|
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Set the content width in pixels, based on the theme's design and stylesheet. |
|
82
|
|
|
* |
|
83
|
|
|
* Priority 0 to make it available to lower priority callbacks. |
|
84
|
|
|
* |
|
85
|
|
|
* @global int $content_width |
|
86
|
|
|
*/ |
|
87
|
|
|
function designfly_content_width() { |
|
88
|
|
|
// This variable is intended to be overruled from themes. |
|
89
|
|
|
// Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}. |
|
90
|
|
|
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound |
|
91
|
|
|
$GLOBALS['content_width'] = apply_filters( 'designfly_content_width', 640 ); |
|
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
add_action( 'after_setup_theme', 'designfly_content_width', 0 ); |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Register widget area. |
|
97
|
|
|
* |
|
98
|
|
|
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar |
|
99
|
|
|
*/ |
|
100
|
|
|
function designfly_widgets_init() { |
|
101
|
|
|
register_sidebar( array( |
|
|
|
|
|
|
102
|
|
|
'name' => esc_html__( 'Sidebar', 'designfly' ), |
|
|
|
|
|
|
103
|
|
|
'id' => 'sidebar-1', |
|
104
|
|
|
'description' => esc_html__( 'Add widgets here.', 'designfly' ), |
|
105
|
|
|
'before_widget' => '<section id="%1$s" class="widget %2$s">', |
|
106
|
|
|
'after_widget' => '</section>', |
|
107
|
|
|
'before_title' => '<h2 class="widget-title">', |
|
108
|
|
|
'after_title' => '</h2>', |
|
109
|
|
|
) ); |
|
110
|
|
|
} |
|
111
|
|
|
add_action( 'widgets_init', 'designfly_widgets_init' ); |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Enqueue scripts and styles. |
|
115
|
|
|
*/ |
|
116
|
|
|
function designfly_scripts() { |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* wp_enqueue_style( string $handle, string $src = '', array $deps = array(), string|bool|null $ver = false, string $media = 'all' ) |
|
120
|
|
|
*/ |
|
121
|
|
|
|
|
122
|
|
|
// dashicons support |
|
123
|
|
|
wp_enqueue_style('dashicons'); |
|
|
|
|
|
|
124
|
|
|
|
|
125
|
|
|
// jquery script |
|
126
|
|
|
wp_enqueue_script( 'jquery', get_template_directory_uri() . '/lib/jquery3.4.1/jquery.js' ); |
|
|
|
|
|
|
127
|
|
|
|
|
128
|
|
|
// bootstrap styles |
|
129
|
|
|
wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/lib/bs-4.3.1/css/bootstrap.min.css' ); |
|
130
|
|
|
|
|
131
|
|
|
// bootstrap scripts |
|
132
|
|
|
wp_enqueue_script( 'bootstrap', get_template_directory_uri() . '/lib/bs-4.3.1/js/bootstrap.min.js', 'jquery', false, true ); |
|
133
|
|
|
|
|
134
|
|
|
// custom css (main style) |
|
135
|
|
|
wp_enqueue_style( 'main-style', get_template_directory_uri() . '/layouts/css/main.css' ); |
|
136
|
|
|
|
|
137
|
|
|
// sidebar style |
|
138
|
|
|
wp_enqueue_style( 'sidebar-style', get_template_directory_uri() . '/layouts/sidebar-content.css' ); |
|
139
|
|
|
|
|
140
|
|
|
// Media queryes |
|
141
|
|
|
wp_enqueue_style( 'media-query', get_template_directory_uri() . '/layouts/css/media-queries.css' ); |
|
142
|
|
|
|
|
143
|
|
|
wp_enqueue_style( 'designfly-style', get_stylesheet_uri() ); |
|
|
|
|
|
|
144
|
|
|
|
|
145
|
|
|
// Main js file |
|
146
|
|
|
wp_enqueue_script( 'main-script', get_template_directory_uri() . '/js/main.js', 'main', false, true ); |
|
147
|
|
|
wp_localize_script( 'main-script', 'directory_name', array( 'templateUrl' => get_stylesheet_directory_uri() ) ); |
|
|
|
|
|
|
148
|
|
|
|
|
149
|
|
|
wp_enqueue_script( 'designfly-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20151215', true ); |
|
150
|
|
|
|
|
151
|
|
|
wp_enqueue_script( 'designfly-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true ); |
|
152
|
|
|
|
|
153
|
|
|
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { |
|
|
|
|
|
|
154
|
|
|
wp_enqueue_script( 'comment-reply' ); |
|
155
|
|
|
} |
|
156
|
|
|
} |
|
157
|
|
|
add_action( 'wp_enqueue_scripts', 'designfly_scripts' ); |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* Implement the Custom Header feature. |
|
161
|
|
|
*/ |
|
162
|
|
|
require get_template_directory() . '/inc/custom-header.php'; |
|
|
|
|
|
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* Custom template tags for this theme. |
|
166
|
|
|
*/ |
|
167
|
|
|
require get_template_directory() . '/inc/template-tags.php'; |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* Functions which enhance the theme by hooking into WordPress. |
|
171
|
|
|
*/ |
|
172
|
|
|
require get_template_directory() . '/inc/template-functions.php'; |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* Customizer additions. |
|
176
|
|
|
*/ |
|
177
|
|
|
require get_template_directory() . '/inc/customizer.php'; |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* Custom widget 'Designfly Portfolio' |
|
181
|
|
|
*/ |
|
182
|
|
|
require get_template_directory() . '/inc/widgets.php'; |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* Load Jetpack compatibility file. |
|
186
|
|
|
*/ |
|
187
|
|
|
if ( defined( 'JETPACK__VERSION' ) ) { |
|
188
|
|
|
require get_template_directory() . '/inc/jetpack.php'; |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* function for maintaining the styling of active class |
|
193
|
|
|
* |
|
194
|
|
|
* @since 1.0.2 |
|
195
|
|
|
*/ |
|
196
|
|
|
function special_nav_class ($classes, $item) { |
|
|
|
|
|
|
197
|
|
|
if (in_array('current-menu-item', $classes) ){ |
|
198
|
|
|
$classes[] = 'active '; |
|
199
|
|
|
} |
|
200
|
|
|
return $classes; |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
add_filter( 'nav_menu_css_class' , 'special_nav_class' , 10 , 2 ); |
|
|
|
|
|
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* function for registering custom post type 'portfolio' |
|
207
|
|
|
* |
|
208
|
|
|
* @since 1.0.3 |
|
209
|
|
|
*/ |
|
210
|
|
|
function designfly_custom_post_type() { |
|
211
|
|
|
|
|
212
|
|
|
$labels = array( |
|
213
|
|
|
'name' => esc_html__( 'Portfolio', 'designfly' ), |
|
|
|
|
|
|
214
|
|
|
'singular_name' => esc_html__( 'Portfolio', 'designfly' ), |
|
215
|
|
|
'add_new' => esc_html__( 'Add Portfolio Item', 'designfly' ), |
|
216
|
|
|
'all_items' => esc_html__( 'All Portfolio Items', 'designfly' ), |
|
217
|
|
|
'add_new_item' => esc_html__( 'Add Portfolio item', 'designfly' ), |
|
218
|
|
|
'edit_item' => esc_html__( 'Edit Portfolio Item', 'designfly' ), |
|
219
|
|
|
'new_item' => esc_html__( 'New Portfolio Item', 'designfly' ), |
|
220
|
|
|
'view_item' => esc_html__( 'View Portfolio Item', 'designfly' ), |
|
221
|
|
|
'search_item' => esc_html__( 'Search Portfolio', 'designfly' ), |
|
222
|
|
|
'not_found' => esc_html__( 'No portfolio items found', 'designfly' ), |
|
223
|
|
|
'not_found_in_trash' => esc_html__( 'No portfolio items found in trash', 'designfly' ), |
|
224
|
|
|
'parent_item_colon' => esc_html__( 'Parent Item', 'designfly' ) |
|
225
|
|
|
); |
|
226
|
|
|
|
|
227
|
|
|
$args = array( |
|
228
|
|
|
'labels' => $labels, |
|
229
|
|
|
'public' => true, |
|
230
|
|
|
'has_archive' => true, |
|
231
|
|
|
'publicly_queryable' => true, |
|
232
|
|
|
'query_var' => true, |
|
233
|
|
|
'rewrite' => true, |
|
234
|
|
|
'capability_type' => 'post', |
|
235
|
|
|
'hierarchical' => false, |
|
236
|
|
|
'menu_icon' => 'dashicons-instagram', |
|
237
|
|
|
'supports' => array( |
|
238
|
|
|
'title', |
|
239
|
|
|
'editor', |
|
240
|
|
|
'excerpt', |
|
241
|
|
|
'thumbnail', |
|
242
|
|
|
'comments', |
|
243
|
|
|
'revision', |
|
244
|
|
|
), |
|
245
|
|
|
'taxonomies' => array( 'category', 'post_tag' ), |
|
246
|
|
|
'menu_position' => 5, |
|
247
|
|
|
'exclude_from_search' => false, |
|
248
|
|
|
'rewrite' => array( 'slug' => 'df-portfolio' ), |
|
249
|
|
|
); |
|
250
|
|
|
|
|
251
|
|
|
register_post_type( 'df-portfolio', $args ); |
|
|
|
|
|
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
add_action( 'init', 'designfly_custom_post_type' ); |
|
255
|
|
|
|
|
256
|
|
|
/** |
|
257
|
|
|
* Filter the "read more" excerpt string link to the post. |
|
258
|
|
|
* |
|
259
|
|
|
* @param string $more "Read more" excerpt string. |
|
260
|
|
|
* @return string (Maybe) modified "read more" excerpt string. |
|
261
|
|
|
* @since 1.0.6 |
|
262
|
|
|
*/ |
|
263
|
|
|
function wpdocs_excerpt_more( $more ) { |
|
264
|
|
|
if ( ! is_single() ) { |
|
|
|
|
|
|
265
|
|
|
$more = sprintf( '<a class="read-more" href="%1$s">%2$s</a>', |
|
266
|
|
|
get_permalink( get_the_ID() ), |
|
|
|
|
|
|
267
|
|
|
__( 'Read More', 'textdomain' ) |
|
|
|
|
|
|
268
|
|
|
); |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
return $more; |
|
272
|
|
|
} |
|
273
|
|
|
add_filter( 'excerpt_more', 'wpdocs_excerpt_more' ); |
|
274
|
|
|
|
|
275
|
|
|
|
|
276
|
|
|
add_filter( 'the_excerpt', 'do_shortcode' ); |
|
277
|
|
|
add_filter( 'widget_text', 'do_shortcode' ); |
|
278
|
|
|
|
|
279
|
|
|
/** |
|
280
|
|
|
* Filter the except length to 20 words. |
|
281
|
|
|
* |
|
282
|
|
|
* @param int $length Excerpt length. |
|
283
|
|
|
* @return int (Maybe) modified excerpt length. |
|
284
|
|
|
* @since 1.0.4 |
|
285
|
|
|
*/ |
|
286
|
|
|
function wpdocs_custom_excerpt_length( $length ) { |
|
|
|
|
|
|
287
|
|
|
return 35; |
|
288
|
|
|
} |
|
289
|
|
|
add_filter( 'excerpt_length', 'wpdocs_custom_excerpt_length', 999 ); |
|
290
|
|
|
|