-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
179 lines (132 loc) · 5.01 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
<?php
require_once(__DIR__ . '/vendor/autoload.php');
$timber = new \Timber\Timber();
class kreationSite extends Timber\Site {
public function __construct() {
add_theme_support( 'post-thumbnails' );
add_theme_support( 'menus' );
add_theme_support(
'html5',
array(
'comment-form',
'comment-list',
'gallery',
'caption',
)
);
add_filter( 'timber_context', array( $this, 'add_to_context' ) );
add_action( 'after_setup_theme', array( $this,'kal_custom_add_image_sizes') );
// TODO: This breaks the theme. Some time in recent years this failed (possibly with an upgrade to WordPress or other plugins)
// See post: https://stackoverflow.com/questions/75688955/image-size-names-choose-not-working-with-wp-timber-theme
//add_filter( 'image_size_names_choose', array($this,'kal_register_custom_image_sizes') );
parent::__construct();
}
function add_to_context( $context ) {
$context['menu'] = new Timber\Menu('main-menu');
$context['site'] = $this;
return $context;
}
}
new kreationSite();
// ========================================================
// Scripts
// ========================================================
/*
add_filter('script_loader_src','add_nonce_to_script',10,2);
function add_nonce_to_script($src, $handle){
$my_nonce = wp_create_nonce('nonce-'.rand());
return $src.' nonce= '.$my_nonce;
}
*/
if ( !is_admin() ) wp_deregister_script('jquery');
function my_deregister_scripts(){
wp_deregister_script( 'wp-embed' );
}
add_action( 'wp_footer', 'my_deregister_scripts' );
// ========================================================
// Images
// ========================================================
function kal_custom_add_image_sizes() {
add_image_size( 'medium150w', 150, 275 );
add_image_size( 'medium200w', 200, 350 );
add_image_size( 'medium300w', 300, 450 );
}
function kal_register_custom_image_sizes( $sizes ) {
return array_merge( $sizes, array(
'medium150w' => __( 'Medium, 150w' ),
'medium200w' => __( 'Medium, 200w' ),
'medium300w' => __( 'Medium, 300w' )
) );
}
// ========================================================
// Custom post types
// ========================================================
function create_posttypes() {
register_post_type( 'project',
array(
'labels' => array(
'name' => __( 'Projects' ),
'singular_name' => __( 'Project' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'projects'),
'show_in_rest' => true,
'taxonomies' => array('category', 'post_tag'),
'supports' => array('title','editor','author','thumbnail','excerpt','trackbacks','custom-fields','comments','revisions','page-attributes')
)
);
}
add_action( 'init', 'create_posttypes' );
// ========================================================
// Shortcodes
// ========================================================
function sc_taglist($atts){
if ( !empty( $atts['postid'] ) ) {
$postid = $atts['postid'];
$postTags = get_the_tags($postid);
if ($postTags) {
foreach ($postTags as $tag) {
$output .= '<div>' . $tag->name . '</div>';
}
} else {
$output = '';
}
return $output;
} else {
return '<div class="tags">' . get_the_tag_list() . '</div>';
}
}
add_shortcode('tags', 'sc_taglist');
// ========================================================
// Miscellaneous
// ========================================================
/* Disable WordPress emoji's */
function disable_emojis() {
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
add_filter( 'tiny_mce_plugins', 'disable_emojis_tinymce' );
add_filter( 'wp_resource_hints', 'disable_emojis_remove_dns_prefetch', 10, 2 );
}
add_action( 'init', 'disable_emojis' );
function disable_emojis_tinymce( $plugins ) {
if ( is_array( $plugins ) ) {
return array_diff( $plugins, array( 'wpemoji' ) );
} else {
return array();
}
}
function disable_emojis_remove_dns_prefetch( $urls, $relation_type ) {
if ( 'dns-prefetch' == $relation_type ) {
// This filter is documented in wp-includes/formatting.php
$emoji_svg_url = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/2/svg/' );
$urls = array_diff( $urls, array( $emoji_svg_url ) );
}
return $urls;
}
?>