/
functions.php
189 lines (157 loc) · 5.3 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
<?php
// Load Theme Scripts and Styles
add_action("wp_enqueue_scripts", "ucla_wordpress_child_load_scripts", 99);
function ucla_wordpress_child_load_scripts() {
wp_enqueue_style( 'ucla-wordpress-child', get_stylesheet_directory_uri() . "/css/ucla-ps.min.css", [], null, "screen" );
}
/**
* Function and filters to remove width|height attributes.
* https://wordpress.stackexchange.com/questions/22302/how-do-you-remove-hard-coded-thumbnail-image-dimensions
* https://petragregorova.com/articles/how-to-remove-height-and-width-attributes-from-images-in-wordpress/
*/
function remove_width_attribute( $html ) {
$html = preg_replace( '/(width|height)="\d*"\s/', "", $html );
return $html;
}
add_filter("post_thumbnail_html", "remove_width_attribute", 10);
add_filter("image_send_to_editor", "remove_width_attribute", 10);
//add_filter( 'the_content', 'remove_thumbnail_dimensions', 10 );
// Filters the returned oEmbed HTML.
// https://developer.wordpress.org/reference/hooks/oembed_dataparse/
add_filter( 'oembed_dataparse', 'remove_width_attribute', 10 );
/**
* Add media alternate image sizes besides WP defaults
* https://developer.wordpress.org/reference/functions/add_image_size/
* add_image_size( string $name, int $width, int $height, bool|array $crop = false )
*/
add_image_size("square", "600", "600", true);
add_image_size("square_thumb", "300", "300", true);
/** REMOVE wp-emoji **/
remove_action("wp_head", "print_emoji_detection_script", 7);
remove_action("wp_print_styles", "print_emoji_styles");
remove_filter( 'render_block', 'wp_render_layout_support_flag', 10, 2 );
//remove_filter( 'render_block', 'gutenberg_render_layout_support_flag', 10, 2 );
// https://managewp.com/hack-improve-wordpress-toolbar
add_action("admin_bar_menu", "ucla_ps_edit_toolbar", 999);
function ucla_ps_edit_toolbar($wp_toolbar)
{
$wp_toolbar->remove_node("updates");
$wp_toolbar->remove_node("comments");
//$wp_toolbar->remove_node('wp-logo');
//$wp_toolbar->remove_node('site-name');
//$wp_toolbar->remove_node('new-content');
//$wp_toolbar->remove_node('top-secondary');
}
/**
* Removes some menus by page.
*/
add_action("admin_menu", "ucla_ps_remove_menus");
function ucla_ps_remove_menus()
{
remove_menu_page("edit-comments.php");
remove_menu_page("link-manager.php"); //Comments
//remove_menu_page( 'index.php' ); //Dashboard
//remove_menu_page( 'jetpack' ); //Jetpack*
//remove_menu_page( 'edit.php' ); //Posts
//remove_menu_page( 'upload.php' ); //Media
//remove_menu_page( 'edit.php?post_type=page' ); //Pages
//remove_menu_page( 'themes.php' ); //Appearance
//remove_menu_page( 'plugins.php' ); //Plugins
//remove_menu_page( 'users.php' ); //Users
//remove_menu_page( 'tools.php' ); //Tools
//remove_menu_page( 'options-general.php' ); //Settings
}
// Breadcrumbs
function get_breadcrumb()
{
echo '<a href="' . home_url() . '" rel="nofollow">Home</a>';
if (is_single()) {
echo " / ";
echo get_post_type(get_the_ID());
// if (is_single()) {
// echo " / ";
// the_title();
// }
} elseif (is_page()) {
// echo " / ";
// echo the_title();
} elseif (is_search()) {
echo " / Search Results for... ";
echo '"<em>';
echo the_search_query();
echo '</em>"';
}
}
function ucla_ps_customizer_settings($wp_customize)
{
$wp_customize->add_setting('ucla_footer_dept_name', array(
'type' => 'theme_mod',
'transport' => 'postMessage',
));
$wp_customize->add_control('ucla_footer_dept_name', array(
'label' => __('Department Name', 'ucla-wordpress'),
'type' => 'text',
'section' => 'ucla_theme_options',
'settings' => 'ucla_footer_dept_name'
));
}
add_action('customize_register', 'ucla_ps_customizer_settings');
/**
* PRINT DATE FUNCTIONS
*/
function custom_datetime_object($field_name)
{
$date = new DateTime($field_name);
echo $date->format("Ymd");
}
function custom_unixtimestamp($field_name)
{
$date = new DateTime($field_name);
echo $date->format("d.m.Y H:i:s");
}
function custom_html_datetime($field_name)
{
$date = new DateTime($field_name);
echo $date->format("Y-m-d H:i");
}
function custom_html_date($field_name)
{
$date = new DateTime($field_name);
echo $date->format("Y-m-d");
}
function custom_html_time($field_name)
{
$date = new DateTime($field_name);
echo $date->format("H:i");
}
function custom_year($field_name)
{
$date = new DateTime($field_name);
echo $date->format("Y");
}
function custom_public_date($field_name)
{
$date = new DateTime($field_name);
echo $date->format("F j, Y");
}
function custom_public_date_day($field_name)
{
$date = new DateTime($field_name);
echo $date->format("l, F j, Y");
}
function custom_public_datetime($field_name)
{
$date = new DateTime($field_name);
echo $date->format("F j, Y, g:i a");
}
function custom_public_time($field_name)
{
$date = new DateTime($field_name);
echo $date->format("g:i a");
}
function custom_public_date_format($field_name, $format)
{
//$format = ('l, F j, Y, g:i a');
$date = new DateTime($field_name);
echo $date->format($format);
}