-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
236 lines (194 loc) · 8.08 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
<?php
/**
* first-edition functions and definitions
*
* @package first-edition
*/
/**
* Set the content width based on the theme's design and stylesheet.
*/
if ( ! isset( $content_width ) ) {
$content_width = 640; /* pixels */
}
if ( ! function_exists( 'first_edition_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function first_edition_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on first-edition, use a find and replace
* to change 'first-edition' to the name of your theme in all the template files
*/
load_theme_textdomain( 'first-edition', get_template_directory() . '/languages' );
// This theme styles the visual editor with editor-style.css to match the theme style.
add_editor_style( 'css/editor-style.css' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
*/
//add_theme_support( 'post-thumbnails' );
// This theme uses wp_nav_menu() in one location.
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'first-edition' ),
) );
// Enable support for Post Formats.
add_theme_support( 'post-formats', array( 'aside', 'image', 'video', 'quote', 'link' ) );
// Enable support for the WordPress core custom background feature.
add_theme_support( 'custom-background', apply_filters( 'first_edition_custom_background_args', array(
'default-color' => 'd7e0df',
'default-image' => '',
) ) );
// Enable support for HTML5 markup.
add_theme_support( 'html5', array(
'comment-list',
'search-form',
'comment-form',
'gallery',
) );
}
endif; // first_edition_setup
add_action( 'after_setup_theme', 'first_edition_setup' );
/**
* Filter previous/next links to loop back to the parent
*/
add_filter( 'previous_post_link', 'first_edition_previous_post_link', 10, 3 );
function first_edition_previous_post_link( $val, $attr, $content = null ) {
global $post;
$parent_link = '<a class="post-parent" href="' . get_permalink( $post->post_parent ) . '" rel="navigation"><span class="meta-nav">←</span> ' . get_the_title( $post->post_parent ) . '</a>';
if ( empty( $post->post_parent ) )
$parent_link = '<a class="post-parent" href="' . home_url() . '" title="' . esc_attr( get_bloginfo( 'name') ) . '" rel="home"><span class="meta-nav">←</span> Home</a>';
$updated_link = '<div class="nav-previous">' . $parent_link . '</div>';
return ( empty( $val ) ) ? $updated_link : $val ;
}
add_filter( 'next_post_link', 'first_edition_next_post_link', 10, 3 );
function first_edition_next_post_link( $val, $attr, $content = null ) {
global $post;
$parent_link = '<a class="post-parent" href="' . get_permalink( $post->post_parent ) . '" rel="navigation">' . get_the_title( $post->post_parent ) . ' <span class="meta-nav">→</span></a>';
if ( empty( $post->post_parent ) )
$parent_link = '<a class="post-parent" href="' . home_url() . '" title="' . esc_attr( get_bloginfo( 'name') ) . '" rel="home">Home <span class="meta-nav">→</span></a>';
$updated_link = '<div class="nav-next">' . $parent_link . '</div>';
return ( empty( $val ) ) ? $updated_link : $val ;
}
add_filter( 'previous_image_link', 'first_edition_previous_image_link', 10, 3 );
function first_edition_previous_image_link( $val, $attr, $content = null ) {
global $post;
$parent_link = '<a class="post-parent" href="' . get_permalink( $post->post_parent ) . '" rel="navigation">←</a>';
return ( empty( $val ) ) ? $parent_link : $val ;
}
add_filter( 'next_image_link', 'first_edition_next_image_link', 10, 3 );
function first_edition_next_image_link( $val, $attr, $content = null ) {
global $post;
$parent_link = '<a class="post-parent" href="' . get_permalink( $post->post_parent ) . '" rel="navigation">→</a>';
return ( empty( $val ) ) ? $parent_link : $val ;
}
/**
* Change the default number of gallery columns.
* Props Viper007Bond for the gist—you are awesome!
*/
add_filter( 'shortcode_atts_gallery', 'first_edition_gallery_default_columns', 10, 3 );
function first_edition_gallery_default_columns( $atts, $defaults, $raw_atts ) {
// Don't override manually-set number of columns
if ( ! empty( $raw_atts['columns'] ) ) {
return $atts;
}
$atts['columns'] = 5;
return $atts;
}
/**
* Change the default image size to large on attachment pages.
*/
add_filter( 'prepend_attachment', 'first_edition_prepend_attachment', 10, 3 );
function first_edition_prepend_attachment() {
$output = '<p>' . wp_get_attachment_link( $id, 'large' ) . '</p>';
return $output;
}
/**
* Add styles from the customizer controls.
*/
function first_edition_customizer_css() {
$logo = get_theme_mod( 'first_edition_logo' );
if ( '' != $logo ) { ?>
<style type="text/css">
.site-branding {
background: url('<?php echo $logo; ?>') no-repeat;
padding-left: 90px;
</style>
<?php }
}
add_action( 'wp_head', 'first_edition_customizer_css' );
/**
* Register widgetized area and update sidebar with default widgets.
*/
function first_edition_widgets_init() {
register_sidebar( array(
'name' => __( 'Sidebar', 'first-edition' ),
'id' => 'sidebar-1',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
}
add_action( 'widgets_init', 'first_edition_widgets_init' );
/**
* Add the bell, shhh. :)
*/
function first_edition_setup_footer() {
$bell = get_theme_mod( 'first_edition_bell', 1 );
if ( $bell > 0 ) { ?>
<script type="text/javascript">
var submitbutton;
submitbutton = document.getElementById('submit');
if ( submitbutton ) {
submitbutton.innerHTML = submitbutton.innerHTML + '<audio id="bell" preload="auto"><source src="<?php echo get_template_directory_uri() . '/inc/bell.wav' ?>"></source></audio>';
submitbutton.onmouseover = function() { document.getElementById('bell').play(); };
}
</script>
<?php }
}
add_action( 'wp_footer', 'first_edition_setup_footer');
/**
* Enqueue scripts and styles.
*/
function first_edition_scripts() {
wp_enqueue_style( 'first-edition-style', get_stylesheet_uri() );
wp_enqueue_script( 'first-edition-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20120206', true );
wp_enqueue_script( 'first-edition-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true );
wp_enqueue_script( 'first-edition-keyboard-shortcuts', get_template_directory_uri() . '/js/keyboard-shortcuts.js', array( 'jquery' ), '20140501', true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
$protocol = is_ssl() ? 'https' : 'http';
wp_enqueue_style( 'quattrocento', "$protocol://fonts.googleapis.com/css?family=Quattrocento:400,700" );
wp_enqueue_style( 'quattrocento-sans', "$protocol://fonts.googleapis.com/css?family=Quattrocento+Sans:400,700" );
}
add_action( 'wp_enqueue_scripts', 'first_edition_scripts' );
/**
* Implement the Custom Header feature.
*/
//require get_template_directory() . '/inc/custom-header.php';
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Custom functions that act independently of the theme templates.
*/
require get_template_directory() . '/inc/extras.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
/**
* Load Jetpack compatibility file.
*/
require get_template_directory() . '/inc/jetpack.php';