-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate-functions.php
69 lines (61 loc) · 1.89 KB
/
template-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
<?php
/**
* Functions which enhance the theme by hooking into WordPress
*
* @package evn
*/
/**
* Adds custom classes to the array of body classes.
*
* @param array $classes Classes for the body element.
* @return array
*/
function evn_body_classes( $classes ) {
// Adds a class of hfeed to non-singular pages.
if ( ! is_singular() ) {
$classes[] = 'hfeed';
}
// Adds a class of no-sidebar when there is no sidebar present.
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
$classes[] = 'no-sidebar';
}
return $classes;
}
add_filter( 'body_class', 'evn_body_classes' );
/**
* Add a pingback url auto-discovery header for single posts, pages, or attachments.
*/
function evn_pingback_header() {
if ( is_singular() && pings_open() ) {
printf( '<link rel="pingback" href="%s">', esc_url( get_bloginfo( 'pingback_url' ) ) );
}
}
add_action( 'wp_head', 'evn_pingback_header' );
function evn_add_hide_title_metabox() {
add_meta_box(
'hide_title_metabox', // Metabox ID
'Hide Title', // Metabox title
'evn_render_hide_title_metabox', // Callback function to render the metabox
'page', // Post type
'side', // Context (normal, advanced, or side)
'default' // Priority (high, core, default, or low)
);
}
add_action( 'add_meta_boxes', 'evn_add_hide_title_metabox' );
function evn_render_hide_title_metabox( $post ) {
$hide_title = get_post_meta( $post->ID, 'hide_title', true );
?>
<label for="hide_title">
<input type="checkbox" name="hide_title" id="hide_title" value="1" <?php checked( $hide_title, 1 ); ?>>
Hide Title
</label>
<?php
}
function evn_save_hide_title_metabox( $post_id ) {
if ( isset( $_POST['hide_title'] ) ) {
update_post_meta( $post_id, 'hide_title', 1 );
} else {
update_post_meta( $post_id, 'hide_title', 0 );
}
}
add_action( 'save_post', 'evn_save_hide_title_metabox' );