-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
549 lines (436 loc) · 16.7 KB
/
functions.php
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
<?php
// Theme setup
function mota_setup() {
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
// Automatic feed
add_theme_support( 'automatic-feed-links' );
// Add nav menu
register_nav_menu( 'primary', __('Primary Menu','mota') );
register_nav_menu( 'footer', __('Footer Menu','mota') );
add_theme_support( 'post-thumbnails' );
add_image_size( 'mota_big-header-xxlarge', 2320, 980, true );
add_image_size( 'mota_big-header-xlarge', 1740, 735, true );
add_image_size( 'mota_big-header-large', 1160, 490, true );
add_image_size( 'mota_big-header-medium', 766, 323, true );
add_image_size( 'mota_big-header-small', 580, 245, true );
add_image_size( 'mota_post-thumbnail-medium', 720, 460, true );
add_image_size( 'mota_post-thumbnail-small', 360, 230, true );
// Make the theme translation ready
load_theme_textdomain('mota', get_template_directory() . '/languages');
// Set content-width
global $content_width;
if ( ! isset( $content_width ) ) $content_width = 882;
}
add_action( 'after_setup_theme', 'mota_setup' );
// Add Custom Logo support
function mota_custom_logo_setup() {
$defaults = array(
'width' => 600,
'height' => 400,
'flex-height' => true,
'flex-width' => true
);
add_theme_support( 'custom-logo', $defaults );
}
add_action( 'after_setup_theme', 'mota_custom_logo_setup' );
if ( ! function_exists( 'mota_fonts_url' ) ) :
function mota_fonts_url() {
$fonts_url = '';
$fonts = array();
$subsets = 'latin,latin-ext';
/* translators: If there are characters in your language that are not supported by Merriweather Sans, translate this to 'off'. Do not translate into your own language. */
if ( 'off' !== _x( 'on', 'Merriweather Sans font: on or off', 'mota' ) ) {
$fonts[] = 'Merriweather Sans:400,700,800';
}
/* translators: If there are characters in your language that are not supported by Merriweather, translate this to 'off'. Do not translate into your own language. */
if ( 'off' !== _x( 'on', 'Merriweather font: on or off', 'mota' ) ) {
$fonts[] = 'Merriweather:400,700,800';
}
/* translators: If there are characters in your language that are not supported by Open Sans, translate this to 'off'. Do not translate into your own language. */
if ( 'off' !== _x( 'on', 'Open Sans font: on or off', 'mota' ) ) {
$fonts[] = 'Open Sans:400,700,800';
}
/* translators: If there are characters in your language that are not supported by Roboto, translate this to 'off'. Do not translate into your own language. */
if ( 'off' !== _x( 'on', 'Roboto font: on or off', 'mota' ) ) {
$fonts[] = 'Roboto:400,700,800';
}
if ( $fonts ) {
$fonts_url = add_query_arg( array(
'family' => urlencode( implode( '|', $fonts ) ),
'subset' => urlencode( $subsets ),
), 'https://fonts.googleapis.com/css' );
}
return $fonts_url;
}
endif;
// Register and enqueue styles
function mota_load_style() {
if ( !is_admin() ) {
// Add custom fonts, used in the main stylesheet.
wp_enqueue_style( 'mota-fonts', mota_fonts_url(), array(), null );
wp_enqueue_style( 'mota_style', get_stylesheet_uri() );
}
}
add_action('wp_enqueue_scripts', 'mota_load_style');
// Enqueue scripts and styles.
function mota_scripts() {
wp_enqueue_script( 'mota-scripts', get_template_directory_uri() . '/js/mota-scripts.js', array( 'jquery' ), '', true);
if ( comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'mota_scripts' );
function mota_sanitize_int( $input, $setting ) {
$input = absint( $input );
// If the input is an absolute integer, return it.
// otherwise, return the default.
return ( $input ? $input : $setting->default );
}
// mota theme options
class mota_Customize {
public static function mota_register ( $wp_customize ) {
// Add Setting for Accent Color
$wp_customize->add_setting( 'accent_color', //No need to use a SERIALIZED name, as `theme_mod` settings already live under one db record
array(
'default' => '#0079a8', //Default setting/value to save
'type' => 'theme_mod', //Is this an 'option' or a 'theme_mod'?
'transport' => 'refresh', //What triggers a refresh of the setting? 'refresh' or 'postMessage' (instant)?
'sanitize_callback' => 'sanitize_hex_color'
)
);
// Add Control for Accent Color
$wp_customize->add_control( new WP_Customize_Color_Control( //Instantiate the color control class
$wp_customize, //Pass the $wp_customize object (required)
'mota_accent_color', //Set a unique ID for the control
array(
'label' => __( 'Accent Color', 'mota' ), //Admin-visible name of the control
'section' => 'colors', //ID of the section this control should render in (can be one of yours, or a WordPress default section)
'settings' => 'accent_color', //Which setting to load and manipulate (serialized is okay)
'priority' => 10, //Determines the order this control appears in for the specified section
)
) );
// Add Setting for Accent Color
$wp_customize->add_setting( 'overlay_color', //No need to use a SERIALIZED name, as `theme_mod` settings already live under one db record
array(
'default' => '#333333', //Default setting/value to save
'type' => 'theme_mod', //Is this an 'option' or a 'theme_mod'?
'transport' => 'refresh', //What triggers a refresh of the setting? 'refresh' or 'postMessage' (instant)?
'sanitize_callback' => 'sanitize_hex_color'
)
);
// Add Control for Accent Color
$wp_customize->add_control( new WP_Customize_Color_Control( //Instantiate the color control class
$wp_customize, //Pass the $wp_customize object (required)
'mota_overlay_color', //Set a unique ID for the control
array(
'label' => __( 'Overlay Color', 'mota' ), //Admin-visible name of the control
'section' => 'colors', //ID of the section this control should render in (can be one of yours, or a WordPress default section)
'settings' => 'overlay_color', //Which setting to load and manipulate (serialized is okay)
'priority' => 20, //Determines the order this control appears in for the specified section
)
) );
$wp_customize->add_section('mota_fonts',
array(
'title' => 'Fonts',
'description' => __( 'Choose between different Fonts.', 'mota' ),
'priority' => 70
)
);
$wp_customize->add_section('mota_posts_pages',
array(
'title' => 'Posts/Pages',
'description' => __( 'Some options for the single post and the page template.', 'mota' ),
'priority' => 75
)
);
// Define Big Header Image on Home
$wp_customize->add_setting(
'mota_home_header',
array(
'default' => 0,
'sanitize_callback' => 'mota_sanitize_int'
)
);
$wp_customize->add_control(
'mota_home_header',
array(
'label' => __( 'Big Header-Image on Front Page is ...', 'mota' ),
'section' => 'mota_posts_pages',
'type' => 'select',
'choices' => array(
0 => __( 'latest/newest Post', 'mota' ),
1 => __( 'latest/newest Sticky Post', 'mota' ),
2 => __( 'hidden', 'mota' )
)
)
);
// Add Two Columns Checkbox
$wp_customize->add_setting(
'mota_two_column_content',
array(
'default' => false,
'sanitize_callback' => 'mota_sanitize_int'
)
);
$wp_customize->add_control(
'mota_two_column_content',
array(
'label' => __( 'Show Content on Single Post/Page in Two Columns', 'mota' ),
'section' => 'mota_posts_pages',
'type' => 'checkbox'
)
);
// Add Font Switcher
$wp_customize->add_setting(
'mota_main_font',
array(
'default' => 'Merriweather Sans'
)
);
$wp_customize->add_control(
'mota_main_font',
array(
'label' => __( 'Main Font (Headlines)', 'mota' ),
'section' => 'mota_fonts',
'type' => 'select',
'choices' => array(
'Merriweather Sans, sans-serif' => 'Merriweather Sans',
'Merriweather, serif' => 'Merriweather',
'Open Sans, sans-serif' => 'Open Sans',
'Roboto, sans-serif' => 'Roboto'
)
)
);
$wp_customize->add_setting(
'mota_second_font',
array(
'default' => 'Merriweather'
)
);
$wp_customize->add_control(
'mota_second_font',
array(
'label' => __( 'Second Font (Text, Teasertext)', 'mota' ),
'section' => 'mota_fonts',
'type' => 'select',
'choices' => array(
'Merriweather Sans, sans-serif' => 'Merriweather Sans',
'Merriweather, serif' => 'Merriweather',
'Open Sans, sans-serif' => 'Open Sans',
'Roboto, sans-serif' => 'Roboto'
)
)
);
$wp_customize->add_setting(
'mota_show_header_singlepost',
array(
'default' => false,
'sanitize_callback' => 'mota_sanitize_int'
)
);
$wp_customize->add_control(
'mota_show_header_singlepost',
array(
'label' => __( 'Show Featured Image on Single Post template', 'mota' ),
'section' => 'mota_posts_pages',
'type' => 'checkbox',
)
);
// Add Hide Date Checkbox
$wp_customize->add_setting('mota_hide_date',array('default' => false,'sanitize_callback' => 'mota_sanitize_int'));
$wp_customize->add_control(
'mota_hide_date',
array(
'label' => __( 'Hide Date in Teasers', 'mota' ),
'section' => 'mota_posts_pages',
'type' => 'checkbox'
)
);
// Add Hide Comments
$wp_customize->add_setting('mota_hide_comments',array('default' => false,'sanitize_callback' => 'mota_sanitize_int'));
$wp_customize->add_control(
'mota_hide_comments',
array(
'label' => __( 'Hide Comments in Teasers', 'mota' ),
'section' => 'mota_posts_pages',
'type' => 'checkbox'
)
);
// Add Hide Author
$wp_customize->add_setting('mota_hide_author',array('default' => false,'sanitize_callback' => 'mota_sanitize_int'));
$wp_customize->add_control(
'mota_hide_author',
array(
'label' => __( 'Hide Author in Teasers', 'mota' ),
'section' => 'mota_posts_pages',
'type' => 'checkbox'
)
);
}
public static function mota_header_output() {
?>
<!-- Customizer CSS -->
<style type="text/css">
<?php
esc_html( self::mota_generate_css('body,.entry h1,.entry h2,.entry h3,.entry h4,.entry h5,.entry h6', 'font-family', 'mota_main_font') );
esc_html( self::mota_generate_css('.teaser-text, .entry', 'font-family', 'mota_second_font') );
esc_html( self::mota_generate_css('#top-section::after,h1.headline-main::after,h3.headline-teaser::after', 'background-color', 'accent_color') );
esc_html( self::mota_generate_css('h2.headline-sub,.article-list article .article-meta a:hover,.footer .footer-navi ul li a:hover,.navigation.pagination .nav-links span.current, .navigation.pagination .nav-links span:hover, .navigation.pagination .nav-links a.current, .navigation.pagination .nav-links a:hover, .header-navigation ul li a:hover, .header-navigation ul li:hover', 'color', 'accent_color') );
esc_html( self::mota_generate_css('#top-section::after', 'background-color', 'overlay_color') );
?>
</style>
<!--/Customizer CSS-->
<?php
}
public static function mota_generate_css( $selector, $style, $mod_name, $prefix='', $postfix='', $echo=true ) {
$return = '';
$mod = esc_attr( get_theme_mod($mod_name) );
if ( ! empty( $mod ) ) {
$return = sprintf('%s { %s:%s; }',
$selector,
$style,
$prefix.$mod.$postfix
);
if ( $echo ) {
echo $return;
}
}
return $return;
}
}
// Setup the Theme Customizer settings and controls...
add_action( 'customize_register' , array( 'mota_Customize' , 'mota_register' ) );
// Output custom CSS to live site
add_action( 'wp_head' , array( 'mota_Customize' , 'mota_header_output' ) );
// Change the length of excerpts
function mota_custom_excerpt_length( $length ) {
if ( is_admin() ) {
return $length;
}
return 42;
}
add_filter( 'excerpt_length', 'mota_custom_excerpt_length', 999 );
// Change the excerpt ellipsis
function mota_new_excerpt_more( $link ) {
if ( is_admin() ) {
return $link;
}
return ' ...';
}
add_filter( 'excerpt_more', 'mota_new_excerpt_more' );
// Return an alternate title, without prefix, for every type used in the get_the_archive_title().
add_filter('get_the_archive_title', function ($title) {
if ( is_category() ) {
$title = single_cat_title( '', false );
} elseif ( is_tag() ) {
$title = single_tag_title( '', false );
} elseif ( is_author() ) {
$title = '<span class="vcard">' . get_the_author() . '</span>';
} elseif ( is_year() ) {
$title = get_the_date( _x( 'Y', 'yearly archives date format', 'mota' ) );
} elseif ( is_month() ) {
$title = get_the_date( _x( 'F Y', 'monthly archives date format', 'mota' ) );
} elseif ( is_day() ) {
$title = get_the_date( _x( 'F j, Y', 'daily archives date format', 'mota' ) );
} elseif ( is_tax( 'post_format' ) ) {
if ( is_tax( 'post_format', 'post-format-aside' ) ) {
$title = _x( 'Asides', 'post format archive title', 'mota' );
} elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) {
$title = _x( 'Galleries', 'post format archive title', 'mota' );
} elseif ( is_tax( 'post_format', 'post-format-image' ) ) {
$title = _x( 'Images', 'post format archive title', 'mota' );
} elseif ( is_tax( 'post_format', 'post-format-video' ) ) {
$title = _x( 'Videos', 'post format archive title', 'mota' );
} elseif ( is_tax( 'post_format', 'post-format-quote' ) ) {
$title = _x( 'Quotes', 'post format archive title', 'mota' );
} elseif ( is_tax( 'post_format', 'post-format-link' ) ) {
$title = _x( 'Links', 'post format archive title', 'mota' );
} elseif ( is_tax( 'post_format', 'post-format-status' ) ) {
$title = _x( 'Statuses', 'post format archive title', 'mota' );
} elseif ( is_tax( 'post_format', 'post-format-audio' ) ) {
$title = _x( 'Audio', 'post format archive title', 'mota' );
} elseif ( is_tax( 'post_format', 'post-format-chat' ) ) {
$title = _x( 'Chats', 'post format archive title', 'mota' );
}
} elseif ( is_post_type_archive() ) {
$title = post_type_archive_title( '', false );
} elseif ( is_tax() ) {
$title = single_term_title( '', false );
} else {
$title = __( 'Archives', 'mota' );
}
return $title;
});
function wpb_move_comment_field_to_bottom( $fields ) {
$comment_field = $fields['comment'];
unset( $fields['comment'] );
$fields['comment'] = $comment_field;
return $fields;
}
add_filter( 'comment_form_fields', 'wpb_move_comment_field_to_bottom' );
if ( is_singular() ) wp_enqueue_script( "comment-reply" );
add_theme_support( 'title-tag' );
add_filter( 'wp_title', 'wpdocs_hack_wp_title_for_home' );
/**
* Customize the title for the home page, if one is not set.
*
* @param string $title The original title.
* @return string The title to use.
*/
function wpdocs_hack_wp_title_for_home( $title )
{
if ( empty( $title ) && ( is_home() || is_front_page() ) ) {
$title = get_bloginfo( 'name', 'display' ) . ' | ' . get_bloginfo( 'description' );
}
return $title;
}
//define( 'ACF_LITE', true );
include_once('advanced-custom-fields/acf.php');
if(function_exists("register_field_group"))
{
register_field_group(array (
'id' => 'acf_subtitle',
'title' => 'Subtitle',
'fields' => array (
array (
'key' => 'field_58a8e1bcf30c3',
'label' => 'Subtitle',
'name' => 'subtitle',
'type' => 'text',
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'formatting' => 'html',
'maxlength' => '',
),
),
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'post',
'order_no' => 0,
'group_no' => 0,
),
),
),
'options' => array (
'position' => 'acf_after_title',
'layout' => 'default',
'hide_on_screen' => array (
),
),
'menu_order' => 0,
));
}
?>