-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
executable file
·641 lines (545 loc) · 22.8 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
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
<?php
/*
* Author: Matthew T Rader | @matthew_t_rader
* URL: matthewtrader.com
* Custom functions, support, custom post types and more.
*/
/*------------------------------------*\
External Modules/Files
\*------------------------------------*/
// Load any external files you have here
/*------------------------------------*\
Theme Support
\*------------------------------------*/
if (!isset($content_width))
{
$content_width = 1600;
}
if (function_exists('add_theme_support'))
{
// Add Menu Support
add_theme_support('menus');
// Add Thumbnail Theme Support
add_theme_support('post-thumbnails');
add_image_size('large', 700, 500, true); // Large Thumbnail
add_image_size('medium', 250, '', true); // Medium Thumbnail
add_image_size('small', 120, '', true); // Small Thumbnail
add_image_size('custom-size', 700, 200, true); // Custom Thumbnail Size call using the_post_thumbnail('custom-size');
add_image_size('homepage-slider-mobile', 768, 768, true); // Large Thumbnail
add_image_size('homepage-slider', 1600, 1600, true); // Large Thumbnail
// Enables post and comment RSS feed links to head
add_theme_support('automatic-feed-links');
// Localisation Support
load_theme_textdomain('ultraPhoto', get_template_directory() . '/languages');
}
/*------------------------------------*\
Functions
\*------------------------------------*/
// Ultra Photo navigation
function ultraPhoto_nav()
{
wp_nav_menu(
array(
'theme_location' => 'header-menu',
'menu' => '',
'container' => 'div',
'container_class' => 'menu-{menu slug}-container',
'container_id' => '',
'menu_class' => 'menu',
'menu_id' => '',
'echo' => true,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul>%3$s</ul>',
'depth' => 0,
'walker' => ''
)
);
}
//Load Ultra Photo scripts (header.php)
function ultraPhoto_header_scripts()
{
// if ($GLOBALS['pagenow'] != 'wp-login.php' && !is_admin()) {
//
// wp_register_script('vendor', get_template_directory_uri() . '/js/vendor/jquery.js', array('jquery'), '1.0.0'); // Custom scripts
// wp_enqueue_script('vendor'); // Enqueue it!
//
// wp_register_script('ultraPhotoscripts', get_template_directory_uri() . '/scripts.js', array('jquery'), '1.0.0'); // Custom scripts
// wp_enqueue_script('ultraPhotoscripts'); // Enqueue it!
//
// }
}
// Load Ultra Photo conditional scripts
function ultraPhoto_conditional_scripts()
{
// if (is_page('pagenamehere')) {
// wp_register_script('scriptname', get_template_directory_uri() . '/js/scriptname.js', array('jquery'), '1.0.0'); // Conditional script(s)
// wp_enqueue_script('scriptname'); // Enqueue it!
// }
}
// Load Ultra Photo styles
function ultraPhoto_styles()
{
// wp_register_style('stylesheet', get_template_directory_uri() . '/style.css', array(), 'all');
// wp_enqueue_style('stylesheet'); // Enqueue it!
}
// Register Ultra Photo Navigation
function register_ultraPhoto_menu()
{
register_nav_menus(array( // Using array to specify more menus if needed
'header-menu' => __('Header Menu', 'ultraPhoto'), // Main Navigation
'sidebar-menu' => __('Sidebar Menu', 'ultraPhoto'), // Sidebar Navigation
'extra-menu' => __('Extra Menu', 'ultraPhoto') // Extra Navigation if needed (duplicate as many as you need!)
));
}
// Remove the <div> surrounding the dynamic navigation to cleanup markup
function my_wp_nav_menu_args($args = '')
{
$args['container'] = false;
return $args;
}
// Remove Injected classes, ID's and Page ID's from Navigation <li> items
function my_css_attributes_filter($var)
{
return is_array($var) ? array() : '';
}
// Remove invalid rel attribute values in the categorylist
function remove_category_rel_from_category_list($thelist)
{
return str_replace('rel="category tag"', 'rel="tag"', $thelist);
}
// Add page slug to body class, love this - Credit: Starkers Wordpress Theme
function add_slug_to_body_class($classes)
{
global $post;
if (is_home()) {
$key = array_search('blog', $classes);
if ($key > -1) {
unset($classes[$key]);
}
} elseif (is_page()) {
$classes[] = sanitize_html_class($post->post_name);
} elseif (is_singular()) {
$classes[] = sanitize_html_class($post->post_name);
}
return $classes;
}
function mytheme_init() {
add_filter('comment_form_defaults','mytheme_comments_form_defaults');
}
add_action('after_setup_theme','mytheme_init');
function mytheme_comments_form_defaults($default) {
unset($default['comment_notes_after']);
return $default;
}
// If Dynamic Sidebar Exists
if (function_exists('register_sidebar'))
{
// Define Sidebar Widget Area 1
register_sidebar(array(
'name' => __('Widget Area 1', 'ultraPhoto'),
'description' => __('Description for this widget-area...', 'ultraPhoto'),
'id' => 'widget-area-1',
'before_widget' => '<div id="%1$s" class="%2$s">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>'
));
// Define Sidebar Widget Area 2
register_sidebar(array(
'name' => __('Widget Area 2', 'ultraPhoto'),
'description' => __('Description for this widget-area...', 'ultraPhoto'),
'id' => 'widget-area-2',
'before_widget' => '<div id="%1$s" class="%2$s">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>'
));
// Define Posts Bottom Content Widget
register_sidebar(array(
'name' => __('Posts Bottom Content Widget', 'ultraPhoto'),
'description' => __('For Content Appearing Below Posts Content', 'ultraPhoto'),
'id' => 'post-bottom-content-widget',
'before_widget' => '<div id="%1$s" class="%2$s">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>'
));
}
add_action('pre_get_posts', 'custom_per_page');
function custom_per_page(&$query) {
if (is_post_type_archive()) {
$query->set('posts_per_page', 24);
}
return;
}
// Remove wp_head() injected Recent Comment styles
function my_remove_recent_comments_style()
{
global $wp_widget_factory;
remove_action('wp_head', array(
$wp_widget_factory->widgets['WP_Widget_Recent_Comments'],
'recent_comments_style'
));
}
// Pagination for paged posts, Page 1, Page 2, Page 3, with Next and Previous Links, No plugin
function ultraPhoto_pagination()
{
global $wp_query;
$big = 999999999;
echo paginate_links(array(
'base' => str_replace($big, '%#%', get_pagenum_link($big)),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'total' => $wp_query->max_num_pages
));
}
// Custom Excerpts
function ultraPhoto_index($length) // Create 20 Word Callback for Index page Excerpts, call using ultraPhoto_excerpt('ultraPhoto_index');
{
return 20;
}
// Create 40 Word Callback for Custom Post Excerpts, call using ultraPhoto_excerpt('ultraPhoto_custom_post');
function ultraPhoto_custom_post($length)
{
return 40;
}
// Create the Custom Excerpts callback
function ultraPhoto_excerpt($length_callback = '', $more_callback = '')
{
global $post;
if (function_exists($length_callback)) {
add_filter('excerpt_length', $length_callback);
}
if (function_exists($more_callback)) {
add_filter('excerpt_more', $more_callback);
}
$output = get_the_excerpt();
$output = apply_filters('wptexturize', $output);
$output = apply_filters('convert_chars', $output);
$output = '<p>' . $output . '</p>';
echo $output;
}
// Custom View Article link to Post
function ultraPhoto_blank_view_article($more)
{
global $post;
return '... <a class="view-article" href="' . get_permalink($post->ID) . '">' . __('View Article', 'ultraPhoto') . '</a>';
}
// Remove Admin bar
function remove_admin_bar()
{
return false;
}
// Remove 'text/css' from our enqueued stylesheet
function ultraPhoto_style_remove($tag)
{
return preg_replace('~\s+type=["\'][^"\']++["\']~', '', $tag);
}
// Remove thumbnail width and height dimensions that prevent fluid images in the_thumbnail
function remove_thumbnail_dimensions( $html )
{
$html = preg_replace('/(width|height)=\"\d*\"\s/', "", $html);
return $html;
}
// Custom Gravatar in Settings > Discussion
function ultraPhotogravatar ($avatar_defaults)
{
$myavatar = get_template_directory_uri() . '/img/gravatar.jpg';
$avatar_defaults[$myavatar] = "Custom Gravatar";
return $avatar_defaults;
}
// Threaded Comments
function enable_threaded_comments()
{
if (!is_admin()) {
if (is_singular() AND comments_open() AND (get_option('thread_comments') == 1)) {
wp_enqueue_script('comment-reply');
}
}
}
// Custom Comments Callback
function ultraPhotocomments($comment, $args, $depth)
{
$GLOBALS['comment'] = $comment;
extract($args, EXTR_SKIP);
if ( 'div' == $args['style'] ) {
$tag = 'div';
$add_below = 'comment';
} else {
$tag = 'li';
$add_below = 'div-comment';
}
?>
<!-- heads up: starting < for the html tag (li or div) in the next line: -->
<<?php echo $tag ?> <?php comment_class(empty( $args['has_children'] ) ? '' : 'parent') ?> id="comment-<?php comment_ID() ?>">
<?php if ( 'div' != $args['style'] ) : ?>
<div id="div-comment-<?php comment_ID() ?>" class="comment-body">
<?php endif; ?>
<div class="comment-author vcard">
<?php if ($args['avatar_size'] != 0) echo get_avatar( $comment, $args['180'] ); ?>
<?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>'), get_comment_author_link()) ?>
</div>
<?php if ($comment->comment_approved == '0') : ?>
<em class="comment-awaiting-moderation"><?php _e('Your comment is awaiting moderation.') ?></em>
<br />
<?php endif; ?>
<div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>">
<?php
printf( __('%1$s at %2$s'), get_comment_date(), get_comment_time()) ?></a><?php edit_comment_link(__('(Edit)'),' ','' );
?>
</div>
<?php comment_text() ?>
<div class="reply">
<?php comment_reply_link(array_merge( $args, array('add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
</div>
<?php if ( 'div' != $args['style'] ) : ?>
</div>
<?php endif; ?>
<?php }
/*------------------------------------*\
Actions + Filters + ShortCodes
\*------------------------------------*/
// Add Actions
add_action('init', 'ultraPhoto_header_scripts'); // Add Custom Scripts to wp_head
add_action('wp_print_scripts', 'ultraPhoto_conditional_scripts'); // Add Conditional Page Scripts
add_action('get_header', 'enable_threaded_comments'); // Enable Threaded Comments
add_action('wp_enqueue_scripts', 'ultraPhoto_styles'); // Add Theme Stylesheet
add_action('init', 'register_ultraPhoto_menu'); // Add Ultra Photo Menu
add_action('init', 'create_post_type_ultraPhoto'); // Add our Ultra Photo Custom Post Type
add_action('widgets_init', 'my_remove_recent_comments_style'); // Remove inline Recent Comment Styles from wp_head()
add_action('init', 'ultraPhoto_pagination'); // Add our ultraPhoto Pagination
// Remove Actions
remove_action('wp_head', 'feed_links_extra', 3); // Display the links to the extra feeds such as category feeds
remove_action('wp_head', 'feed_links', 2); // Display the links to the general feeds: Post and Comment Feed
remove_action('wp_head', 'rsd_link'); // Display the link to the Really Simple Discovery service endpoint, EditURI link
remove_action('wp_head', 'wlwmanifest_link'); // Display the link to the Windows Live Writer manifest file.
remove_action('wp_head', 'index_rel_link'); // Index link
remove_action('wp_head', 'parent_post_rel_link', 10, 0); // Prev link
remove_action('wp_head', 'start_post_rel_link', 10, 0); // Start link
remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0); // Display relational links for the posts adjacent to the current post.
remove_action('wp_head', 'wp_generator'); // Display the XHTML generator that is generated on the wp_head hook, WP version
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
remove_action('wp_head', 'rel_canonical');
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
// Add Filters
add_filter('avatar_defaults', 'ultraPhotogravatar'); // Custom Gravatar in Settings > Discussion
add_filter('body_class', 'add_slug_to_body_class'); // Add slug to body class (Starkers build)
add_filter('widget_text', 'do_shortcode'); // Allow shortcodes in Dynamic Sidebar
add_filter('widget_text', 'shortcode_unautop'); // Remove <p> tags in Dynamic Sidebars (better!)
add_filter('wp_nav_menu_args', 'my_wp_nav_menu_args'); // Remove surrounding <div> from WP Navigation
// add_filter('nav_menu_css_class', 'my_css_attributes_filter', 100, 1); // Remove Navigation <li> injected classes (Commented out by default)
// add_filter('nav_menu_item_id', 'my_css_attributes_filter', 100, 1); // Remove Navigation <li> injected ID (Commented out by default)
// add_filter('page_css_class', 'my_css_attributes_filter', 100, 1); // Remove Navigation <li> Page ID's (Commented out by default)
add_filter('the_category', 'remove_category_rel_from_category_list'); // Remove invalid rel attribute
add_filter('the_excerpt', 'shortcode_unautop'); // Remove auto <p> tags in Excerpt (Manual Excerpts only)
add_filter('the_excerpt', 'do_shortcode'); // Allows Shortcodes to be executed in Excerpt (Manual Excerpts only)
add_filter('excerpt_more', 'ultraPhoto_blank_view_article'); // Add 'View Article' button instead of [...] for Excerpts
add_filter('style_loader_tag', 'ultraPhoto_style_remove'); // Remove 'text/css' from enqueued stylesheet
add_filter('post_thumbnail_html', 'remove_thumbnail_dimensions', 10); // Remove width and height dynamic attributes to thumbnails
add_filter('image_send_to_editor', 'remove_thumbnail_dimensions', 10); // Remove width and height dynamic attributes to post images
// Remove Filters
remove_filter('the_excerpt', 'wpautop'); // Remove <p> tags from Excerpt altogether
// Shortcodes
add_shortcode('ultraPhoto_shortcode_demo', 'ultraPhoto_shortcode_demo'); // You can place [ultraPhoto_shortcode_demo] in Pages, Posts now.
add_shortcode('ultraPhoto_shortcode_demo_2', 'ultraPhoto_shortcode_demo_2'); // Place [ultraPhoto_shortcode_demo_2] in Pages, Posts now.
// Shortcodes above would be nested like this -
// [ultraPhoto_shortcode_demo] [ultraPhoto_shortcode_demo_2] Here's the page title! [/ultraPhoto_shortcode_demo_2] [/ultraPhoto_shortcode_demo]
/*------------------------------------*\
Custom Post Types
\*------------------------------------*/
// Create 1 Custom Post type for a Demo, called ultraPhoto-Blank
function create_post_type_ultraPhoto()
{
register_taxonomy_for_object_type('category', 'ultraPhoto-blank'); // Register Taxonomies for Category
register_taxonomy_for_object_type('post_tag', 'ultraPhoto-blank');
register_post_type('ultraPhoto-blank', // Register Custom Post Type
array(
'labels' => array(
'name' => __('Ultra Photo Custom Post', 'ultraPhoto'), // Rename these to suit
'singular_name' => __('Ultra Photo Custom Post', 'ultraPhoto'),
'add_new' => __('Add New', 'ultraPhoto'),
'add_new_item' => __('Add New Ultra Photo Custom Post', 'ultraPhoto'),
'edit' => __('Edit', 'ultraPhoto'),
'edit_item' => __('Edit Ultra Photo Custom Post', 'ultraPhoto'),
'new_item' => __('New Ultra Photo Custom Post', 'ultraPhoto'),
'view' => __('View Ultra Photo Custom Post', 'ultraPhoto'),
'view_item' => __('View Ultra Photo Custom Post', 'ultraPhoto'),
'search_items' => __('Search Ultra Photo Custom Post', 'ultraPhoto'),
'not_found' => __('No Ultra Photo Custom Posts found', 'ultraPhoto'),
'not_found_in_trash' => __('No Ultra Photo Custom Posts found in Trash', 'ultraPhoto')
),
'public' => false,
'hierarchical' => true, // Allows your posts to behave like Hierarchy Pages
'has_archive' => true,
'supports' => array(
'title',
'editor',
'excerpt',
'thumbnail'
), // Go to Dashboard Custom Ultra Photo post for supports
'can_export' => true, // Allows export in Tools > Export
'taxonomies' => array(
'post_tag',
'category'
) // Add Category and Post Tags support
));
}
/*------------------------------------*\
ShortCode Functions
\*------------------------------------*/
// Shortcode Demo with Nested Capability
function ultraPhoto_shortcode_demo($atts, $content = null)
{
return '<div class="shortcode-demo">' . do_shortcode($content) . '</div>'; // do_shortcode allows for nested Shortcodes
}
// Shortcode Demo with simple <h2> tag
function ultraPhoto_shortcode_demo_2($atts, $content = null) // Demo Heading H2 shortcode, allows for nesting within above element. Fully expandable.
{
return '<h2>' . $content . '</h2>';
}
//add hatom data
function add_suf_hatom_data($content) {
$t = get_the_modified_time('F jS, Y');
$author = get_the_author();
$title = get_the_title();
if (is_home() || is_singular() || is_archive() ) {
$content .= '<div class="hatom-extra"><span class="entry-title">'.$title.'</span> was last modified: <span class="updated"> '.$t.'</span> by <span class="author vcard"><span class="fn">'.$author.'</span></span></div>';
}
return $content;
}
add_filter('the_content', 'add_suf_hatom_data');
function add_alt_tags($content)
{
global $post;
preg_match_all('/<img (.*?)\/>/', $content, $images);
if(!is_null($images))
{
foreach($images[1] as $index => $value)
{
if(!preg_match('/alt=/', $value))
{
$new_img = str_replace('<img', '<img alt="'.$post->post_title.'"', $images[0][$index]);
$content = str_replace($images[0][$index], $new_img, $content);
}
}
}
return $content;
}
add_filter('the_content', 'add_alt_tags', 99999);
function jetpackme_filter_exclude_category( $filters ) {
$filters[] = array( 'not' =>
array( 'term' => array( 'category.slug' => 'no-related' ) )
);
return $filters;
}
add_filter( 'jetpack_relatedposts_filter_filters', 'jetpackme_filter_exclude_category' );
add_filter('post_gallery', 'my_post_gallery', 10, 2);
function my_post_gallery($output, $attr) {
global $post;
if (isset($attr['orderby'])) {
$attr['orderby'] = sanitize_sql_orderby($attr['orderby']);
if (!$attr['orderby'])
unset($attr['orderby']);
}
extract(shortcode_atts(array(
'order' => 'ASC',
'orderby' => 'menu_order ID',
'id' => $post->ID,
'itemtag' => 'dl',
'icontag' => 'dt',
'captiontag' => 'dd',
'columns' => 3,
'size' => 'thumbnail',
'include' => '',
'exclude' => ''
), $attr));
$id = intval($id);
if ('RAND' == $order) $orderby = 'none';
if (!empty($include)) {
$include = preg_replace('/[^0-9,]+/', '', $include);
$_attachments = get_posts(array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));
$attachments = array();
foreach ($_attachments as $key => $val) {
$attachments[$val->ID] = $_attachments[$key];
}
}
if (empty($attachments)) return '';
// Here's your actual output, you may customize it to your need
$output = "<div class=\"gallery\">\n";
$thumb_id = get_post_thumbnail_id(get_the_ID());
$alt = get_post_meta($thumb_id, '_wp_attachment_image_alt', true); if( $alt ): endif;
// Now you loop through each attachment
foreach ($attachments as $id => $attachment) {
// Fetch the thumbnail (or full image, it's up to you)
// $img = wp_get_attachment_image_src($id, 'medium');
// $img = wp_get_attachment_image_src($id, 'my-custom-image-size');
$img = wp_get_attachment_image_src($id, 'full');
$output .= "<amp-img layout=\"responsive\" src=\"{$img[0]}\" width=\"{$img[1]}\" height=\"{$img[2]}\" alt=\"{$alt}\" />\n";
$output .= "</amp-img>\n";
}
$output .= "</div>\n";
return $output;
}
// Remove jQuery Migrate Script from header and Load jQuery from Google API
function crunchify_stop_loading_wp_embed_and_jquery() {
if (!is_admin()) {
wp_deregister_script('wp-embed');
wp_deregister_script('jquery'); // Bonus: remove jquery too if it's not required
}
}
add_action('init', 'crunchify_stop_loading_wp_embed_and_jquery');
function ultraPhoto_theme_customizer( $wp_customize ) {
// Add logo image field to customizer
$wp_customize->add_setting( 'ultraPhoto_logo' );
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'ultraPhoto_logo', array(
'label' => __( 'Logo', 'ultraPhoto' ),
'section' => 'title_tagline',
'settings' => 'ultraPhoto_logo',
) ) );
// Add logo width to customizer
$wp_customize->add_setting( 'ultraPhoto_number_setting_w', array(
'capability' => 'edit_theme_options',
'sanitize_callback' => 'ultraPhoto_sanitize_number_absint',
'default' => 7,
) );
$wp_customize->add_control( 'ultraPhoto_number_setting_w', array(
'type' => 'number',
'section' => 'title_tagline',
'label' => __( 'Logo Width' ),
'description' => __( "Add height and width to make the logo maintain it's ratio for amp" ),
) );
// Add logo height to customizer
$wp_customize->add_setting( 'ultraPhoto_number_setting_h', array(
'capability' => 'edit_theme_options',
'sanitize_callback' => 'ultraPhoto_sanitize_number_absint',
'default' => 5,
) );
$wp_customize->add_control( 'ultraPhoto_number_setting_h', array(
'type' => 'number',
'section' => 'title_tagline',
'label' => __( 'Logo Height' ),
) );
function ultraPhoto_sanitize_number_absint( $number, $setting ) {
// Ensure $number is an absolute integer (whole number, zero or greater).
$number = absint( $number );
// If the input is an absolute integer, return it; otherwise, return the default
return ( $number ? $number : $setting->default );
}
}
add_action( 'customize_register', 'ultraPhoto_theme_customizer' );
/**
*
* @param Checks for ssl returns https if needed
* @param int $p
* @return filter
*/
function get_theme_mod_img($mod_name){
return str_replace(array('http:', 'https:'), '', get_theme_mod($mod_name));
}
?>