-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
261 lines (224 loc) · 8.21 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
<?php
define("THEME_DIR", get_template_directory_uri());
/*--- REMOVE GENERATOR META TAG ---*/
remove_action('wp_head', 'wp_generator');
// REMOVE WP EMOJI
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
//Remove Gutenberg Block Library CSS from loading on the frontend
// function smartwp_remove_wp_block_library_css(){
// wp_dequeue_style( 'wp-block-library' );
// wp_dequeue_style( 'wp-block-library-theme' );
// }
// add_action( 'wp_enqueue_scripts', 'smartwp_remove_wp_block_library_css' );
// Disable REST API link tag
remove_action('wp_head', 'rest_output_link_wp_head', 10);
// Disable oEmbed Discovery Links
remove_action('wp_head', 'wp_oembed_add_discovery_links', 10);
// Disable REST API link in HTTP headers
remove_action('template_redirect', 'rest_output_link_header', 11, 0);
// Remove the links to xmlrpc.php and wlwmanifest.xml
function removeHeadLinks() {
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
}
add_action('init', 'removeHeadLinks');
//Remove blocks library css
function wpassist_remove_block_library_css(){
wp_dequeue_style( 'wp-block-library' );
}
add_action( 'wp_enqueue_scripts', 'wpassist_remove_block_library_css' );
//
function my_deregister_scripts(){
wp_deregister_script( 'wp-embed' );
}
add_action( 'wp_footer', 'my_deregister_scripts' );
//This code will limit WordPress to only save your last 4 revisions of each post or page, and discard older revisions automatically.
define( 'WP_POST_REVISIONS', 4 );
function theme_slug_setup() {
add_theme_support( 'title-tag' );
}
add_action( 'after_setup_theme', 'theme_slug_setup' );
//Add custom menu functionality
function new_custom_menu() {
register_nav_menu('my-custom-menu',__( 'My Custom Menu' ));
}
add_action( 'init', 'new_custom_menu' );
function add_additional_class_on_li($classes, $item, $args) {
if(isset($args->add_li_class)) {
$classes[] = $args->add_li_class;
}
return $classes;
}
add_filter('nav_menu_css_class', 'add_additional_class_on_li', 1, 3);
/**
* Add custom image sizes attribute to enhance responsive image functionality
* for content images.
*/
function image_sizes_attr( $sizes, $size ) {
$width = $size[0];
$sizes = '(max-width: 640px) 100vw, (max-width: 768px) 80vw, (max-width: 928px) 60vw, 80vw';
return $sizes;
}
add_filter( 'wp_calculate_image_sizes', 'image_sizes_attr', 10, 2 );
// /**
// * Add custom CSS and JS
// */
// function my_load_scripts($hook) {
//
// // create my own version codes
// //$my_js_ver = date("ymd-Gis", filemtime( plugin_dir_path( __FILE__ ) . 'js/custom.js' ));
// //$my_css_ver = date("ymd-Gis", filemtime( plugin_dir_path( __FILE__ ) . 'style.css' ));
//
// wp_enqueue_script( 'custom_js', get_template_directory_uri() . '/js/min/custom-min.js', array(), '1.0.0', true );
// //wp_enqueue_script( 'custom_js', plugins_url( 'js/custom.js', __FILE__ ), array(), $my_js_ver );
// //wp_register_style( 'my_css', plugins_url( 'style.css', __FILE__ ), false, $my_css_ver );
// //wp_enqueue_style ( 'my_css' );
//
// }
// add_action('wp_enqueue_scripts', 'my_load_scripts');
// SHORTCODES
// The portfolio post
function show_portfolio_post( $atts ) {
$post = $atts[post];
$post = get_page_by_path( $post, OBJECT, 'portfolio' ); //slug
if ( $post ) {
$post_excerpt = $post->post_excerpt;
$post_link = get_permalink( $post );
$post_image = get_the_post_thumbnail( $post );
$post_ID = $post->ID;
$post_color = get_post_meta( $post_ID, 'color_meta', 1) ;
$post_size = $atts[size];
$post_style = '';
if ( $post_color ) {
$post_style = 'style="background-color:' . $post_color . '"';
}
$post_class = '';
if ( $post_size ) {
$post_class = ' ' . $post_size;
}
$return_string = '<article class="project' . $post_class . '" ' . $post_style . '>';
$return_string .= '<header>';
$return_string .= '<h1>' . $post_excerpt . '</h1>';
$return_string .= '<a class="button white" href="' . $post_link . '">Learn more</a>';
$return_string .= '</header>';
if ( $post_image ) {
$return_string .= '<figure>' . $post_image . '</figure>';
}
$return_string .= '</article>';
wp_reset_query();
return $return_string;
}
}
add_shortcode('portfolio-post','show_portfolio_post');
// The testimonial post
function show_testimonial_post( $atts ) {
$post = $atts[post];
$post = get_page_by_path( $post, OBJECT, 'testimonial' ); //slug
if ( $post ) {
$post_title = $post->post_title;
$post_excerpt = $post->post_excerpt;
$post_content = $post->post_content;
$post_image = get_the_post_thumbnail( $post );
$return_string = '<blockquote class="testimonial">';
$return_string .= '<header>';
$return_string .= '<figure>' . $post_image . '</figure>';
$return_string .= '<figcaption><cite>' . $post_title . '</cite><span>' . $post_excerpt . '</span></figcaption>';
$return_string .= '</header>';
$return_string .= $post_content;
$return_string .= '</blockquote>';
wp_reset_query();
return $return_string;
}
}
add_shortcode('testimonial-post','show_testimonial_post');
// Add classes to body
add_filter( 'body_class','my_body_classes' );
function my_body_classes( $classes ) {
global $post;
if ( isset( $post ) ) {
$classes[] = $post->post_type . '-' . $post->post_name;
}
// Check if there's a custom body-color from post custom-fields
if ( $body_color = get_post_meta( $post->ID, 'body-color', true ) ) {
$classes[] = $body_color;
}
return $classes;
}
//Enable SVG upload
// function add_svg_to_upload_mimes( $upload_mimes ) {
// $upload_mimes['svg'] = 'image/svg+xml';
// $upload_mimes['svgz'] = 'image/svg+xml';
// return $upload_mimes;
// }
// add_filter( 'upload_mimes', 'add_svg_to_upload_mimes', 10, 1 );
//Enable thumbnails for CPT - featured image
add_theme_support( 'post-thumbnails' );
//CPT Portfolio
add_action( 'init', 'portfolio_post_type' );
function portfolio_post_type() {
register_post_type( 'portfolio',
array(
'labels' => array(
'name' => __( 'Portfolio' ),
'singular_name' => __( 'Project' ),
'add_new_item' => __( 'Add New Project' )
),
'public' => true,
'show_in_rest' => true,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
'menu_position' => 5,
'menu_icon' => 'dashicons-image-filter'
)
);
}
//CPT Testimonial
add_action( 'init', 'testimonial_post_type' );
function testimonial_post_type() {
register_post_type( 'testimonial',
array(
'labels' => array(
'name' => __( 'Testimonials' ),
'singular_name' => __( 'Testimonial' ),
'add_new_item' => __( 'Add New Testimonial' )
),
'public' => true,
'show_in_rest' => true,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
'menu_position' => 6,
'menu_icon' => 'dashicons-image-filter'
)
);
}
//PORTFOLIO PROJECT META
add_action("admin_init", "admin_init");
function admin_init(){
add_meta_box("cover_meta", "Cover text", "cover_meta", "portfolio", "side", "high");
add_meta_box("color_meta", "Background color (hex)", "color_meta", "portfolio", "side", "low");
}
function cover_meta(){
global $post;
$custom = get_post_custom($post->ID);
$cover_meta = $custom["cover_meta"][0];
?>
<label for="cover_meta">Text that will appear on the page cover.</label>
<textarea name="cover_meta" rows="4" style="width:100%;"><?php echo $cover_meta; ?></textarea>
<?php
}
function color_meta(){
global $post;
$custom = get_post_custom($post->ID);
$color_meta = $custom["color_meta"][0];
?>
<input name="color_meta" value="<?php echo $color_meta; ?>" />
<?php
}
add_action('save_post', 'save_details');
function save_details(){
global $post;
update_post_meta($post->ID, "cover_meta", $_POST["cover_meta"]);
update_post_meta($post->ID, "color_meta", $_POST["color_meta"]);
}
?>