3 * General template tags that can go anywhere in a template.
10 * Load header template.
12 * Includes the header template for a theme or if a name is specified then a
13 * specialised header will be included.
15 * For the parameter, if the file is called "header-special.php" then specify
20 * @uses locate_template()
22 * @param string $name The name of the specialised header.
24 function get_header( $name = null ) {
26 * Fires before the header template file is loaded.
28 * The hook allows a specific header template file to be used in place of the
29 * default header template file. If your file is called header-new.php,
30 * you would specify the filename in the hook as get_header( 'new' ).
33 * @since 2.8.0 $name parameter added.
35 * @param string $name Name of the specific header file to use.
37 do_action( 'get_header', $name );
40 $name = (string) $name;
42 $templates[] = "header-{$name}.php";
44 $templates[] = 'header.php';
46 // Backward compat code will be removed in a future release
47 if ('' == locate_template($templates, true))
48 load_template( ABSPATH . WPINC . '/theme-compat/header.php');
52 * Load footer template.
54 * Includes the footer template for a theme or if a name is specified then a
55 * specialised footer will be included.
57 * For the parameter, if the file is called "footer-special.php" then specify
62 * @uses locate_template()
64 * @param string $name The name of the specialised footer.
66 function get_footer( $name = null ) {
68 * Fires before the footer template file is loaded.
70 * The hook allows a specific footer template file to be used in place of the
71 * default footer template file. If your file is called footer-new.php,
72 * you would specify the filename in the hook as get_footer( 'new' ).
75 * @since 2.8.0 $name parameter added.
77 * @param string $name Name of the specific footer file to use.
79 do_action( 'get_footer', $name );
82 $name = (string) $name;
84 $templates[] = "footer-{$name}.php";
86 $templates[] = 'footer.php';
88 // Backward compat code will be removed in a future release
89 if ('' == locate_template($templates, true))
90 load_template( ABSPATH . WPINC . '/theme-compat/footer.php');
94 * Load sidebar template.
96 * Includes the sidebar template for a theme or if a name is specified then a
97 * specialised sidebar will be included.
99 * For the parameter, if the file is called "sidebar-special.php" then specify
104 * @uses locate_template()
106 * @param string $name The name of the specialised sidebar.
108 function get_sidebar( $name = null ) {
110 * Fires before the sidebar template file is loaded.
112 * The hook allows a specific sidebar template file to be used in place of the
113 * default sidebar template file. If your file is called sidebar-new.php,
114 * you would specify the filename in the hook as get_sidebar( 'new' ).
117 * @since 2.8.0 $name parameter added.
119 * @param string $name Name of the specific sidebar file to use.
121 do_action( 'get_sidebar', $name );
123 $templates = array();
124 $name = (string) $name;
126 $templates[] = "sidebar-{$name}.php";
128 $templates[] = 'sidebar.php';
130 // Backward compat code will be removed in a future release
131 if ('' == locate_template($templates, true))
132 load_template( ABSPATH . WPINC . '/theme-compat/sidebar.php');
136 * Load a template part into a template
138 * Makes it easy for a theme to reuse sections of code in a easy to overload way
141 * Includes the named template part for a theme or if a name is specified then a
142 * specialised part will be included. If the theme contains no {slug}.php file
143 * then no template will be included.
145 * The template is included using require, not require_once, so you may include the
146 * same template part multiple times.
148 * For the $name parameter, if the file is called "{slug}-special.php" then specify
153 * @uses locate_template()
155 * @param string $slug The slug name for the generic template.
156 * @param string $name The name of the specialised template.
158 function get_template_part( $slug, $name = null ) {
160 * Fires before the specified template part file is loaded.
162 * The dynamic portion of the hook name, $slug, refers to the slug name
163 * for the generic template part.
167 * @param string $slug The slug name for the generic template.
168 * @param string $name The name of the specialized template.
170 do_action( "get_template_part_{$slug}", $slug, $name );
172 $templates = array();
173 $name = (string) $name;
175 $templates[] = "{$slug}-{$name}.php";
177 $templates[] = "{$slug}.php";
179 locate_template($templates, true, false);
183 * Display search form.
185 * Will first attempt to locate the searchform.php file in either the child or
186 * the parent, then load it. If it doesn't exist, then the default search form
187 * will be displayed. The default search form is HTML, which will be displayed.
188 * There is a filter applied to the search form HTML in order to edit or replace
189 * it. The filter is 'get_search_form'.
191 * This function is primarily used by themes which want to hardcode the search
192 * form into the sidebar and also by the search widget in WordPress.
194 * There is also an action that is called whenever the function is run called,
195 * 'pre_get_search_form'. This can be useful for outputting JavaScript that the
196 * search relies on or various formatting that applies to the beginning of the
197 * search. To give a few examples of what it can be used for.
201 * @param boolean $echo Default to echo and not return the form.
202 * @return string|null String when retrieving, null when displaying or if searchform.php exists.
204 function get_search_form( $echo = true ) {
206 * Fires before the search form is retrieved, at the start of get_search_form().
208 * @since 2.7.0 as 'get_search_form' action.
211 * @link https://core.trac.wordpress.org/ticket/19321
213 do_action( 'pre_get_search_form' );
215 $format = current_theme_supports( 'html5', 'search-form' ) ? 'html5' : 'xhtml';
218 * Filter the HTML format of the search form.
222 * @param string $format The type of markup to use in the search form.
223 * Accepts 'html5', 'xhtml'.
225 $format = apply_filters( 'search_form_format', $format );
227 $search_form_template = locate_template( 'searchform.php' );
228 if ( '' != $search_form_template ) {
230 require( $search_form_template );
231 $form = ob_get_clean();
233 if ( 'html5' == $format ) {
234 $form = '<form role="search" method="get" class="search-form" action="' . esc_url( home_url( '/' ) ) . '">
236 <span class="screen-reader-text">' . _x( 'Search for:', 'label' ) . '</span>
237 <input type="search" class="search-field" placeholder="' . esc_attr_x( 'Search …', 'placeholder' ) . '" value="' . get_search_query() . '" name="s" title="' . esc_attr_x( 'Search for:', 'label' ) . '" />
239 <input type="submit" class="search-submit" value="'. esc_attr_x( 'Search', 'submit button' ) .'" />
242 $form = '<form role="search" method="get" id="searchform" class="searchform" action="' . esc_url( home_url( '/' ) ) . '">
244 <label class="screen-reader-text" for="s">' . _x( 'Search for:', 'label' ) . '</label>
245 <input type="text" value="' . get_search_query() . '" name="s" id="s" />
246 <input type="submit" id="searchsubmit" value="'. esc_attr_x( 'Search', 'submit button' ) .'" />
253 * Filter the HTML output of the search form.
257 * @param string $form The search form HTML output.
259 $result = apply_filters( 'get_search_form', $form );
261 if ( null === $result )
271 * Display the Log In/Out link.
273 * Displays a link, which allows users to navigate to the Log In page to log in
274 * or log out depending on whether they are currently logged in.
278 * @param string $redirect Optional path to redirect to on login/logout.
279 * @param boolean $echo Default to echo and not return the link.
280 * @return string|null String when retrieving, null when displaying.
282 function wp_loginout($redirect = '', $echo = true) {
283 if ( ! is_user_logged_in() )
284 $link = '<a href="' . esc_url( wp_login_url($redirect) ) . '">' . __('Log in') . '</a>';
286 $link = '<a href="' . esc_url( wp_logout_url($redirect) ) . '">' . __('Log out') . '</a>';
290 * Filter the HTML output for the Log In/Log Out link.
294 * @param string $link The HTML link content.
296 echo apply_filters( 'loginout', $link );
298 /** This filter is documented in wp-includes/general-template.php */
299 return apply_filters( 'loginout', $link );
304 * Returns the Log Out URL.
306 * Returns the URL that allows the user to log out of the site.
310 * @uses wp_nonce_url() To protect against CSRF.
311 * @uses site_url() To generate the log out URL.
313 * @param string $redirect Path to redirect to on logout.
314 * @return string A log out URL.
316 function wp_logout_url($redirect = '') {
317 $args = array( 'action' => 'logout' );
318 if ( !empty($redirect) ) {
319 $args['redirect_to'] = urlencode( $redirect );
322 $logout_url = add_query_arg($args, site_url('wp-login.php', 'login'));
323 $logout_url = wp_nonce_url( $logout_url, 'log-out' );
326 * Filter the logout URL.
330 * @param string $logout_url The Log Out URL.
331 * @param string $redirect Path to redirect to on logout.
333 return apply_filters( 'logout_url', $logout_url, $redirect );
337 * Returns the Log In URL.
339 * Returns the URL that allows the user to log in to the site.
343 * @uses site_url() To generate the log in URL.
345 * @param string $redirect Path to redirect to on login.
346 * @param bool $force_reauth Whether to force reauthorization, even if a cookie is present. Default is false.
347 * @return string A log in URL.
349 function wp_login_url($redirect = '', $force_reauth = false) {
350 $login_url = site_url('wp-login.php', 'login');
352 if ( !empty($redirect) )
353 $login_url = add_query_arg('redirect_to', urlencode($redirect), $login_url);
356 $login_url = add_query_arg('reauth', '1', $login_url);
359 * Filter the login URL.
363 * @param string $login_url The login URL.
364 * @param string $redirect The path to redirect to on login, if supplied.
366 return apply_filters( 'login_url', $login_url, $redirect );
370 * Returns the user registration URL.
372 * Returns the URL that allows the user to register on the site.
376 * @uses site_url() To generate the registration URL.
378 * @return string User registration URL.
380 function wp_registration_url() {
382 * Filter the user registration URL.
386 * @param string $register The user registration URL.
388 return apply_filters( 'register_url', site_url( 'wp-login.php?action=register', 'login' ) );
392 * Provides a simple login form for use anywhere within WordPress. By default, it echoes
393 * the HTML immediately. Pass array('echo'=>false) to return the string instead.
397 * @param array $args Configuration options to modify the form output.
398 * @return string|null String when retrieving, null when displaying.
400 function wp_login_form( $args = array() ) {
403 'redirect' => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], // Default redirect is back to the current page
404 'form_id' => 'loginform',
405 'label_username' => __( 'Username' ),
406 'label_password' => __( 'Password' ),
407 'label_remember' => __( 'Remember Me' ),
408 'label_log_in' => __( 'Log In' ),
409 'id_username' => 'user_login',
410 'id_password' => 'user_pass',
411 'id_remember' => 'rememberme',
412 'id_submit' => 'wp-submit',
414 'value_username' => '',
415 'value_remember' => false, // Set this to true to default the "Remember me" checkbox to checked
419 * Filter the default login form output arguments.
423 * @see wp_login_form()
425 * @param array $defaults An array of default login form arguments.
427 $args = wp_parse_args( $args, apply_filters( 'login_form_defaults', $defaults ) );
430 * Filter content to display at the top of the login form.
432 * The filter evaluates just following the opening form tag element.
436 * @param string $content Content to display. Default empty.
437 * @param array $args Array of login form arguments.
439 $login_form_top = apply_filters( 'login_form_top', '', $args );
442 * Filter content to display in the middle of the login form.
444 * The filter evaluates just following the location where the 'login-password'
445 * field is displayed.
449 * @param string $content Content to display. Default empty.
450 * @param array $args Array of login form arguments.
452 $login_form_middle = apply_filters( 'login_form_middle', '', $args );
455 * Filter content to display at the bottom of the login form.
457 * The filter evaluates just preceding the closing form tag element.
461 * @param string $content Content to display. Default empty.
462 * @param array $args Array of login form arguments.
464 $login_form_bottom = apply_filters( 'login_form_bottom', '', $args );
467 <form name="' . $args['form_id'] . '" id="' . $args['form_id'] . '" action="' . esc_url( site_url( 'wp-login.php', 'login_post' ) ) . '" method="post">
468 ' . $login_form_top . '
469 <p class="login-username">
470 <label for="' . esc_attr( $args['id_username'] ) . '">' . esc_html( $args['label_username'] ) . '</label>
471 <input type="text" name="log" id="' . esc_attr( $args['id_username'] ) . '" class="input" value="' . esc_attr( $args['value_username'] ) . '" size="20" />
473 <p class="login-password">
474 <label for="' . esc_attr( $args['id_password'] ) . '">' . esc_html( $args['label_password'] ) . '</label>
475 <input type="password" name="pwd" id="' . esc_attr( $args['id_password'] ) . '" class="input" value="" size="20" />
477 ' . $login_form_middle . '
478 ' . ( $args['remember'] ? '<p class="login-remember"><label><input name="rememberme" type="checkbox" id="' . esc_attr( $args['id_remember'] ) . '" value="forever"' . ( $args['value_remember'] ? ' checked="checked"' : '' ) . ' /> ' . esc_html( $args['label_remember'] ) . '</label></p>' : '' ) . '
479 <p class="login-submit">
480 <input type="submit" name="wp-submit" id="' . esc_attr( $args['id_submit'] ) . '" class="button-primary" value="' . esc_attr( $args['label_log_in'] ) . '" />
481 <input type="hidden" name="redirect_to" value="' . esc_url( $args['redirect'] ) . '" />
483 ' . $login_form_bottom . '
493 * Returns the Lost Password URL.
495 * Returns the URL that allows the user to retrieve the lost password
499 * @uses site_url() To generate the lost password URL
501 * @param string $redirect Path to redirect to on login.
502 * @return string Lost password URL.
504 function wp_lostpassword_url( $redirect = '' ) {
505 $args = array( 'action' => 'lostpassword' );
506 if ( !empty($redirect) ) {
507 $args['redirect_to'] = $redirect;
510 $lostpassword_url = add_query_arg( $args, network_site_url('wp-login.php', 'login') );
513 * Filter the Lost Password URL.
517 * @param string $lostpassword_url The lost password page URL.
518 * @param string $redirect The path to redirect to on login.
520 return apply_filters( 'lostpassword_url', $lostpassword_url, $redirect );
524 * Display the Registration or Admin link.
526 * Display a link which allows the user to navigate to the registration page if
527 * not logged in and registration is enabled or to the dashboard if logged in.
531 * @param string $before Text to output before the link (defaults to <li>).
532 * @param string $after Text to output after the link (defaults to </li>).
533 * @param boolean $echo Default to echo and not return the link.
534 * @return string|null String when retrieving, null when displaying.
536 function wp_register( $before = '<li>', $after = '</li>', $echo = true ) {
538 if ( ! is_user_logged_in() ) {
539 if ( get_option('users_can_register') )
540 $link = $before . '<a href="' . esc_url( wp_registration_url() ) . '">' . __('Register') . '</a>' . $after;
544 $link = $before . '<a href="' . admin_url() . '">' . __('Site Admin') . '</a>' . $after;
548 * Filter the HTML link to the Registration or Admin page.
550 * Users are sent to the admin page if logged-in, or the registration page
551 * if enabled and logged-out.
555 * @param string $link The HTML code for the link to the Registration or Admin page.
557 $link = apply_filters( 'register', $link );
567 * Theme container function for the 'wp_meta' action.
569 * The 'wp_meta' action can have several purposes, depending on how you use it,
570 * but one purpose might have been to allow for theme switching.
574 * @link http://trac.wordpress.org/ticket/1458 Explanation of 'wp_meta' action.
578 * Fires before displaying echoed content in the sidebar.
582 do_action( 'wp_meta' );
586 * Display information about the blog.
588 * @see get_bloginfo() For possible values for the parameter.
591 * @param string $show What to display.
593 function bloginfo( $show='' ) {
594 echo get_bloginfo( $show, 'display' );
598 * Retrieve information about the blog.
600 * Some show parameter values are deprecated and will be removed in future
601 * versions. These options will trigger the _deprecated_argument() function.
602 * The deprecated blog info options are listed in the function contents.
604 * The possible values for the 'show' parameter are listed below.
606 * <li><strong>url</strong> - Blog URI to homepage.</li>
607 * <li><strong>wpurl</strong> - Blog URI path to WordPress.</li>
608 * <li><strong>description</strong> - Secondary title</li>
611 * The feed URL options can be retrieved from 'rdf_url' (RSS 0.91),
612 * 'rss_url' (RSS 1.0), 'rss2_url' (RSS 2.0), or 'atom_url' (Atom feed). The
613 * comment feeds can be retrieved from the 'comments_atom_url' (Atom comment
614 * feed) or 'comments_rss2_url' (RSS 2.0 comment feed).
618 * @param string $show Blog info to retrieve.
619 * @param string $filter How to filter what is retrieved.
620 * @return string Mostly string values, might be empty.
622 function get_bloginfo( $show = '', $filter = 'raw' ) {
625 case 'home' : // DEPRECATED
626 case 'siteurl' : // DEPRECATED
627 _deprecated_argument( __FUNCTION__, '2.2', sprintf( __('The <code>%s</code> option is deprecated for the family of <code>bloginfo()</code> functions.' ), $show ) . ' ' . sprintf( __( 'Use the <code>%s</code> option instead.' ), 'url' ) );
629 $output = home_url();
632 $output = site_url();
635 $output = get_option('blogdescription');
638 $output = get_feed_link('rdf');
641 $output = get_feed_link('rss');
644 $output = get_feed_link('rss2');
647 $output = get_feed_link('atom');
649 case 'comments_atom_url':
650 $output = get_feed_link('comments_atom');
652 case 'comments_rss2_url':
653 $output = get_feed_link('comments_rss2');
656 $output = site_url( 'xmlrpc.php' );
658 case 'stylesheet_url':
659 $output = get_stylesheet_uri();
661 case 'stylesheet_directory':
662 $output = get_stylesheet_directory_uri();
664 case 'template_directory':
666 $output = get_template_directory_uri();
669 $output = get_option('admin_email');
672 $output = get_option('blog_charset');
673 if ('' == $output) $output = 'UTF-8';
676 $output = get_option('html_type');
680 $output = $wp_version;
683 $output = get_locale();
684 $output = str_replace('_', '-', $output);
686 case 'text_direction':
687 //_deprecated_argument( __FUNCTION__, '2.2', sprintf( __('The <code>%s</code> option is deprecated for the family of <code>bloginfo()</code> functions.' ), $show ) . ' ' . sprintf( __( 'Use the <code>%s</code> function instead.' ), 'is_rtl()' ) );
688 if ( function_exists( 'is_rtl' ) ) {
689 $output = is_rtl() ? 'rtl' : 'ltr';
696 $output = get_option('blogname');
701 if (strpos($show, 'url') === false &&
702 strpos($show, 'directory') === false &&
703 strpos($show, 'home') === false)
706 if ( 'display' == $filter ) {
709 * Filter the URL returned by get_bloginfo().
713 * @param mixed $output The URL returned by bloginfo().
714 * @param mixed $show Type of information requested.
716 $output = apply_filters( 'bloginfo_url', $output, $show );
719 * Filter the site information returned by get_bloginfo().
723 * @param mixed $output The requested non-URL site information.
724 * @param mixed $show Type of information requested.
726 $output = apply_filters( 'bloginfo', $output, $show );
734 * Display or retrieve page title for all areas of blog.
736 * By default, the page title will display the separator before the page title,
737 * so that the blog title will be before the page title. This is not good for
738 * title display, since the blog title shows up on most tabs and not what is
739 * important, which is the page that the user is looking at.
741 * There are also SEO benefits to having the blog title after or to the 'right'
742 * or the page title. However, it is mostly common sense to have the blog title
743 * to the right with most browsers supporting tabs. You can achieve this by
744 * using the seplocation parameter and setting the value to 'right'. This change
745 * was introduced around 2.5.0, in case backwards compatibility of themes is
750 * @param string $sep Optional, default is '»'. How to separate the various items within the page title.
751 * @param bool $display Optional, default is true. Whether to display or retrieve title.
752 * @param string $seplocation Optional. Direction to display title, 'right'.
753 * @return string|null String on retrieve, null when displaying.
755 function wp_title($sep = '»', $display = true, $seplocation = '') {
758 $m = get_query_var('m');
759 $year = get_query_var('year');
760 $monthnum = get_query_var('monthnum');
761 $day = get_query_var('day');
762 $search = get_query_var('s');
765 $t_sep = '%WP_TITILE_SEP%'; // Temporary separator, for accurate flipping, if necessary
767 // If there is a post
768 if ( is_single() || ( is_home() && !is_front_page() ) || ( is_page() && !is_front_page() ) ) {
769 $title = single_post_title( '', false );
772 // If there's a post type archive
773 if ( is_post_type_archive() ) {
774 $post_type = get_query_var( 'post_type' );
775 if ( is_array( $post_type ) )
776 $post_type = reset( $post_type );
777 $post_type_object = get_post_type_object( $post_type );
778 if ( ! $post_type_object->has_archive )
779 $title = post_type_archive_title( '', false );
782 // If there's a category or tag
783 if ( is_category() || is_tag() ) {
784 $title = single_term_title( '', false );
787 // If there's a taxonomy
789 $term = get_queried_object();
791 $tax = get_taxonomy( $term->taxonomy );
792 $title = single_term_title( $tax->labels->name . $t_sep, false );
796 // If there's an author
797 if ( is_author() && ! is_post_type_archive() ) {
798 $author = get_queried_object();
800 $title = $author->display_name;
803 // Post type archives with has_archive should override terms.
804 if ( is_post_type_archive() && $post_type_object->has_archive )
805 $title = post_type_archive_title( '', false );
807 // If there's a month
808 if ( is_archive() && !empty($m) ) {
809 $my_year = substr($m, 0, 4);
810 $my_month = $wp_locale->get_month(substr($m, 4, 2));
811 $my_day = intval(substr($m, 6, 2));
812 $title = $my_year . ( $my_month ? $t_sep . $my_month : '' ) . ( $my_day ? $t_sep . $my_day : '' );
816 if ( is_archive() && !empty($year) ) {
818 if ( !empty($monthnum) )
819 $title .= $t_sep . $wp_locale->get_month($monthnum);
821 $title .= $t_sep . zeroise($day, 2);
826 /* translators: 1: separator, 2: search phrase */
827 $title = sprintf(__('Search Results %1$s %2$s'), $t_sep, strip_tags($search));
830 // If it's a 404 page
832 $title = __('Page not found');
836 if ( !empty($title) )
840 * Filter the parts of the page title.
844 * @param array $title_array Parts of the page title.
846 $title_array = apply_filters( 'wp_title_parts', explode( $t_sep, $title ) );
848 // Determines position of the separator and direction of the breadcrumb
849 if ( 'right' == $seplocation ) { // sep on right, so reverse the order
850 $title_array = array_reverse( $title_array );
851 $title = implode( " $sep ", $title_array ) . $prefix;
853 $title = $prefix . implode( " $sep ", $title_array );
857 * Filter the text of the page title.
861 * @param string $title Page title.
862 * @param string $sep Title separator.
863 * @param string $seplocation Location of the separator (left or right).
865 $title = apply_filters( 'wp_title', $title, $sep, $seplocation );
876 * Display or retrieve page title for post.
878 * This is optimized for single.php template file for displaying the post title.
880 * It does not support placing the separator after the title, but by leaving the
881 * prefix parameter empty, you can set the title separator manually. The prefix
882 * does not automatically place a space between the prefix, so if there should
883 * be a space, the parameter value will need to have it at the end.
887 * @param string $prefix Optional. What to display before the title.
888 * @param bool $display Optional, default is true. Whether to display or retrieve title.
889 * @return string|null Title when retrieving, null when displaying or failure.
891 function single_post_title($prefix = '', $display = true) {
892 $_post = get_queried_object();
894 if ( !isset($_post->post_title) )
898 * Filter the page title for a single post.
902 * @param string $_post_title The single post page title.
903 * @param object $_post The current queried object as returned by get_queried_object().
905 $title = apply_filters( 'single_post_title', $_post->post_title, $_post );
907 echo $prefix . $title;
909 return $prefix . $title;
913 * Display or retrieve title for a post type archive.
915 * This is optimized for archive.php and archive-{$post_type}.php template files
916 * for displaying the title of the post type.
920 * @param string $prefix Optional. What to display before the title.
921 * @param bool $display Optional, default is true. Whether to display or retrieve title.
922 * @return string|null Title when retrieving, null when displaying or failure.
924 function post_type_archive_title( $prefix = '', $display = true ) {
925 if ( ! is_post_type_archive() )
928 $post_type = get_query_var( 'post_type' );
929 if ( is_array( $post_type ) )
930 $post_type = reset( $post_type );
932 $post_type_obj = get_post_type_object( $post_type );
935 * Filter the post type archive title.
939 * @param string $post_type_name Post type 'name' label.
940 * @param string $post_type Post type.
942 $title = apply_filters( 'post_type_archive_title', $post_type_obj->labels->name, $post_type );
945 echo $prefix . $title;
947 return $prefix . $title;
951 * Display or retrieve page title for category archive.
953 * This is useful for category template file or files, because it is optimized
954 * for category page title and with less overhead than {@link wp_title()}.
956 * It does not support placing the separator after the title, but by leaving the
957 * prefix parameter empty, you can set the title separator manually. The prefix
958 * does not automatically place a space between the prefix, so if there should
959 * be a space, the parameter value will need to have it at the end.
963 * @param string $prefix Optional. What to display before the title.
964 * @param bool $display Optional, default is true. Whether to display or retrieve title.
965 * @return string|null Title when retrieving, null when displaying or failure.
967 function single_cat_title( $prefix = '', $display = true ) {
968 return single_term_title( $prefix, $display );
972 * Display or retrieve page title for tag post archive.
974 * Useful for tag template files for displaying the tag page title. It has less
975 * overhead than {@link wp_title()}, because of its limited implementation.
977 * It does not support placing the separator after the title, but by leaving the
978 * prefix parameter empty, you can set the title separator manually. The prefix
979 * does not automatically place a space between the prefix, so if there should
980 * be a space, the parameter value will need to have it at the end.
984 * @param string $prefix Optional. What to display before the title.
985 * @param bool $display Optional, default is true. Whether to display or retrieve title.
986 * @return string|null Title when retrieving, null when displaying or failure.
988 function single_tag_title( $prefix = '', $display = true ) {
989 return single_term_title( $prefix, $display );
993 * Display or retrieve page title for taxonomy term archive.
995 * Useful for taxonomy term template files for displaying the taxonomy term page title.
996 * It has less overhead than {@link wp_title()}, because of its limited implementation.
998 * It does not support placing the separator after the title, but by leaving the
999 * prefix parameter empty, you can set the title separator manually. The prefix
1000 * does not automatically place a space between the prefix, so if there should
1001 * be a space, the parameter value will need to have it at the end.
1005 * @param string $prefix Optional. What to display before the title.
1006 * @param bool $display Optional, default is true. Whether to display or retrieve title.
1007 * @return string|null Title when retrieving, null when displaying or failure.
1009 function single_term_title( $prefix = '', $display = true ) {
1010 $term = get_queried_object();
1015 if ( is_category() ) {
1017 * Filter the category archive page title.
1021 * @param string $term_name Category name for archive being displayed.
1023 $term_name = apply_filters( 'single_cat_title', $term->name );
1024 } elseif ( is_tag() ) {
1026 * Filter the tag archive page title.
1030 * @param string $term_name Tag name for archive being displayed.
1032 $term_name = apply_filters( 'single_tag_title', $term->name );
1033 } elseif ( is_tax() ) {
1035 * Filter the custom taxonomy archive page title.
1039 * @param string $term_name Term name for archive being displayed.
1041 $term_name = apply_filters( 'single_term_title', $term->name );
1046 if ( empty( $term_name ) )
1050 echo $prefix . $term_name;
1052 return $prefix . $term_name;
1056 * Display or retrieve page title for post archive based on date.
1058 * Useful for when the template only needs to display the month and year, if
1059 * either are available. Optimized for just this purpose, so if it is all that
1060 * is needed, should be better than {@link wp_title()}.
1062 * It does not support placing the separator after the title, but by leaving the
1063 * prefix parameter empty, you can set the title separator manually. The prefix
1064 * does not automatically place a space between the prefix, so if there should
1065 * be a space, the parameter value will need to have it at the end.
1069 * @param string $prefix Optional. What to display before the title.
1070 * @param bool $display Optional, default is true. Whether to display or retrieve title.
1071 * @return string|null Title when retrieving, null when displaying or failure.
1073 function single_month_title($prefix = '', $display = true ) {
1076 $m = get_query_var('m');
1077 $year = get_query_var('year');
1078 $monthnum = get_query_var('monthnum');
1080 if ( !empty($monthnum) && !empty($year) ) {
1082 $my_month = $wp_locale->get_month($monthnum);
1083 } elseif ( !empty($m) ) {
1084 $my_year = substr($m, 0, 4);
1085 $my_month = $wp_locale->get_month(substr($m, 4, 2));
1088 if ( empty($my_month) )
1091 $result = $prefix . $my_month . $prefix . $my_year;
1099 * Retrieve archive link content based on predefined or custom code.
1101 * The format can be one of four styles. The 'link' for head element, 'option'
1102 * for use in the select element, 'html' for use in list (either ol or ul HTML
1103 * elements). Custom content is also supported using the before and after
1106 * The 'link' format uses the link HTML element with the <em>archives</em>
1107 * relationship. The before and after parameters are not used. The text
1108 * parameter is used to describe the link.
1110 * The 'option' format uses the option HTML element for use in select element.
1111 * The value is the url parameter and the before and after parameters are used
1112 * between the text description.
1114 * The 'html' format, which is the default, uses the li HTML element for use in
1115 * the list HTML elements. The before parameter is before the link and the after
1116 * parameter is after the closing link.
1118 * The custom format uses the before parameter before the link ('a' HTML
1119 * element) and the after parameter after the closing link tag. If the above
1120 * three values for the format are not used, then custom format is assumed.
1124 * @param string $url URL to archive.
1125 * @param string $text Archive text description.
1126 * @param string $format Optional, default is 'html'. Can be 'link', 'option', 'html', or custom.
1127 * @param string $before Optional.
1128 * @param string $after Optional.
1129 * @return string HTML link content for archive.
1131 function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') {
1132 $text = wptexturize($text);
1133 $url = esc_url($url);
1135 if ('link' == $format)
1136 $link_html = "\t<link rel='archives' title='" . esc_attr( $text ) . "' href='$url' />\n";
1137 elseif ('option' == $format)
1138 $link_html = "\t<option value='$url'>$before $text $after</option>\n";
1139 elseif ('html' == $format)
1140 $link_html = "\t<li>$before<a href='$url'>$text</a>$after</li>\n";
1142 $link_html = "\t$before<a href='$url'>$text</a>$after\n";
1145 * Filter the archive link content.
1149 * @param string $link_html The archive HTML link content.
1151 $link_html = apply_filters( 'get_archives_link', $link_html );
1157 * Display archive links based on type and format.
1161 * @see get_archives_link()
1163 * @param string|array $args {
1164 * Default archive links arguments. Optional.
1166 * @type string $type Type of archive to retrieve. Accepts 'daily', 'weekly', 'monthly',
1167 * 'yearly', 'postbypost', or 'alpha'. Both 'postbypost' and 'alpha'
1168 * display the same archive link list as well as post titles instead
1169 * of displaying dates. The difference between the two is that 'alpha'
1170 * will order by post title and 'postbypost' will order by post date.
1171 * Default 'monthly'.
1172 * @type string|int $limit Number of links to limit the query to. Default empty (no limit).
1173 * @type string $format Format each link should take using the $before and $after args.
1174 * Accepts 'link' (`<link>` tag), 'option' (`<option>` tag), 'html'
1175 * (`<li>` tag), or a custom format, which generates a link anchor
1176 * with $before preceding and $after succeeding. Default 'html'.
1177 * @type string $before Markup to prepend to the beginning of each link. Default empty.
1178 * @type string $after Markup to append to the end of each link. Default empty.
1179 * @type bool $show_post_count Whether to display the post count alongside the link. Default false.
1180 * @type bool $echo Whether to echo or return the links list. Default 1|true to echo.
1181 * @type string $order Whether to use ascending or descending order. Accepts 'ASC', or 'DESC'.
1184 * @return string|null String when retrieving, null when displaying.
1186 function wp_get_archives( $args = '' ) {
1187 global $wpdb, $wp_locale;
1190 'type' => 'monthly', 'limit' => '',
1191 'format' => 'html', 'before' => '',
1192 'after' => '', 'show_post_count' => false,
1193 'echo' => 1, 'order' => 'DESC',
1196 $r = wp_parse_args( $args, $defaults );
1198 if ( '' == $r['type'] ) {
1199 $r['type'] = 'monthly';
1202 if ( ! empty( $r['limit'] ) ) {
1203 $r['limit'] = absint( $r['limit'] );
1204 $r['limit'] = ' LIMIT ' . $r['limit'];
1207 $order = strtoupper( $r['order'] );
1208 if ( $order !== 'ASC' ) {
1212 // this is what will separate dates on weekly archive links
1213 $archive_week_separator = '–';
1215 // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride
1216 $archive_date_format_over_ride = 0;
1218 // options for daily archive (only if you over-ride the general date format)
1219 $archive_day_date_format = 'Y/m/d';
1221 // options for weekly archive (only if you over-ride the general date format)
1222 $archive_week_start_date_format = 'Y/m/d';
1223 $archive_week_end_date_format = 'Y/m/d';
1225 if ( ! $archive_date_format_over_ride ) {
1226 $archive_day_date_format = get_option( 'date_format' );
1227 $archive_week_start_date_format = get_option( 'date_format' );
1228 $archive_week_end_date_format = get_option( 'date_format' );
1232 * Filter the SQL WHERE clause for retrieving archives.
1236 * @param string $sql_where Portion of SQL query containing the WHERE clause.
1237 * @param array $r An array of default arguments.
1239 $where = apply_filters( 'getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r );
1242 * Filter the SQL JOIN clause for retrieving archives.
1246 * @param string $sql_join Portion of SQL query containing JOIN clause.
1247 * @param array $r An array of default arguments.
1249 $join = apply_filters( 'getarchives_join', '', $r );
1253 $last_changed = wp_cache_get( 'last_changed', 'posts' );
1254 if ( ! $last_changed ) {
1255 $last_changed = microtime();
1256 wp_cache_set( 'last_changed', $last_changed, 'posts' );
1259 $limit = $r['limit'];
1261 if ( 'monthly' == $r['type'] ) {
1262 $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date $order $limit";
1263 $key = md5( $query );
1264 $key = "wp_get_archives:$key:$last_changed";
1265 if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
1266 $results = $wpdb->get_results( $query );
1267 wp_cache_set( $key, $results, 'posts' );
1270 $after = $r['after'];
1271 foreach ( (array) $results as $result ) {
1272 $url = get_month_link( $result->year, $result->month );
1273 /* translators: 1: month name, 2: 4-digit year */
1274 $text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $result->month ), $result->year );
1275 if ( $r['show_post_count'] ) {
1276 $r['after'] = ' (' . $result->posts . ')' . $after;
1278 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
1281 } elseif ( 'yearly' == $r['type'] ) {
1282 $query = "SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date) ORDER BY post_date $order $limit";
1283 $key = md5( $query );
1284 $key = "wp_get_archives:$key:$last_changed";
1285 if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
1286 $results = $wpdb->get_results( $query );
1287 wp_cache_set( $key, $results, 'posts' );
1290 $after = $r['after'];
1291 foreach ( (array) $results as $result) {
1292 $url = get_year_link( $result->year );
1293 $text = sprintf( '%d', $result->year );
1294 if ( $r['show_post_count'] ) {
1295 $r['after'] = ' (' . $result->posts . ')' . $after;
1297 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
1300 } elseif ( 'daily' == $r['type'] ) {
1301 $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date $order $limit";
1302 $key = md5( $query );
1303 $key = "wp_get_archives:$key:$last_changed";
1304 if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
1305 $results = $wpdb->get_results( $query );
1306 $cache[ $key ] = $results;
1307 wp_cache_set( $key, $results, 'posts' );
1310 $after = $r['after'];
1311 foreach ( (array) $results as $result ) {
1312 $url = get_day_link( $result->year, $result->month, $result->dayofmonth );
1313 $date = sprintf( '%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth );
1314 $text = mysql2date( $archive_day_date_format, $date );
1315 if ( $r['show_post_count'] ) {
1316 $r['after'] = ' (' . $result->posts . ')' . $after;
1318 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
1321 } elseif ( 'weekly' == $r['type'] ) {
1322 $week = _wp_mysql_week( '`post_date`' );
1323 $query = "SELECT DISTINCT $week AS `week`, YEAR( `post_date` ) AS `yr`, DATE_FORMAT( `post_date`, '%Y-%m-%d' ) AS `yyyymmdd`, count( `ID` ) AS `posts` FROM `$wpdb->posts` $join $where GROUP BY $week, YEAR( `post_date` ) ORDER BY `post_date` $order $limit";
1324 $key = md5( $query );
1325 $key = "wp_get_archives:$key:$last_changed";
1326 if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
1327 $results = $wpdb->get_results( $query );
1328 wp_cache_set( $key, $results, 'posts' );
1332 $after = $r['after'];
1333 foreach ( (array) $results as $result ) {
1334 if ( $result->week != $arc_w_last ) {
1335 $arc_year = $result->yr;
1336 $arc_w_last = $result->week;
1337 $arc_week = get_weekstartend( $result->yyyymmdd, get_option( 'start_of_week' ) );
1338 $arc_week_start = date_i18n( $archive_week_start_date_format, $arc_week['start'] );
1339 $arc_week_end = date_i18n( $archive_week_end_date_format, $arc_week['end'] );
1340 $url = sprintf( '%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', home_url(), '', '?', '=', $arc_year, '&', '=', $result->week );
1341 $text = $arc_week_start . $archive_week_separator . $arc_week_end;
1342 if ( $r['show_post_count'] ) {
1343 $r['after'] = ' (' . $result->posts . ')' . $after;
1345 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
1349 } elseif ( ( 'postbypost' == $r['type'] ) || ('alpha' == $r['type'] ) ) {
1350 $orderby = ( 'alpha' == $r['type'] ) ? 'post_title ASC ' : 'post_date DESC ';
1351 $query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit";
1352 $key = md5( $query );
1353 $key = "wp_get_archives:$key:$last_changed";
1354 if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
1355 $results = $wpdb->get_results( $query );
1356 wp_cache_set( $key, $results, 'posts' );
1359 foreach ( (array) $results as $result ) {
1360 if ( $result->post_date != '0000-00-00 00:00:00' ) {
1361 $url = get_permalink( $result );
1362 if ( $result->post_title ) {
1363 /** This filter is documented in wp-includes/post-template.php */
1364 $text = strip_tags( apply_filters( 'the_title', $result->post_title, $result->ID ) );
1366 $text = $result->ID;
1368 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
1381 * Get number of days since the start of the week.
1385 * @param int $num Number of day.
1386 * @return int Days since the start of the week.
1388 function calendar_week_mod($num) {
1390 return ($num - $base*floor($num/$base));
1394 * Display calendar with days that have posts as links.
1396 * The calendar is cached, which will be retrieved, if it exists. If there are
1397 * no posts for the month, then it will not be displayed.
1400 * @uses calendar_week_mod()
1402 * @param bool $initial Optional, default is true. Use initial calendar names.
1403 * @param bool $echo Optional, default is true. Set to false for return.
1404 * @return string|null String when retrieving, null when displaying.
1406 function get_calendar($initial = true, $echo = true) {
1407 global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
1409 $key = md5( $m . $monthnum . $year );
1410 if ( $cache = wp_cache_get( 'get_calendar', 'calendar' ) ) {
1411 if ( is_array($cache) && isset( $cache[ $key ] ) ) {
1413 /** This filter is documented in wp-includes/general-template.php */
1414 echo apply_filters( 'get_calendar', $cache[$key] );
1417 /** This filter is documented in wp-includes/general-template.php */
1418 return apply_filters( 'get_calendar', $cache[$key] );
1423 if ( !is_array($cache) )
1426 // Quick check. If we have no posts at all, abort!
1428 $gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1");
1430 $cache[ $key ] = '';
1431 wp_cache_set( 'get_calendar', $cache, 'calendar' );
1436 if ( isset($_GET['w']) )
1437 $w = ''.intval($_GET['w']);
1439 // week_begins = 0 stands for Sunday
1440 $week_begins = intval(get_option('start_of_week'));
1442 // Let's figure out when we are
1443 if ( !empty($monthnum) && !empty($year) ) {
1444 $thismonth = ''.zeroise(intval($monthnum), 2);
1445 $thisyear = ''.intval($year);
1446 } elseif ( !empty($w) ) {
1447 // We need to get the month from MySQL
1448 $thisyear = ''.intval(substr($m, 0, 4));
1449 $d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's
1450 $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')");
1451 } elseif ( !empty($m) ) {
1452 $thisyear = ''.intval(substr($m, 0, 4));
1453 if ( strlen($m) < 6 )
1456 $thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2);
1458 $thisyear = gmdate('Y', current_time('timestamp'));
1459 $thismonth = gmdate('m', current_time('timestamp'));
1462 $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear);
1463 $last_day = date('t', $unixmonth);
1465 // Get the next and previous month and year with at least one post
1466 $previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
1468 WHERE post_date < '$thisyear-$thismonth-01'
1469 AND post_type = 'post' AND post_status = 'publish'
1470 ORDER BY post_date DESC
1472 $next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
1474 WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59'
1475 AND post_type = 'post' AND post_status = 'publish'
1476 ORDER BY post_date ASC
1479 /* translators: Calendar caption: 1: month name, 2: 4-digit year */
1480 $calendar_caption = _x('%1$s %2$s', 'calendar caption');
1481 $calendar_output = '<table id="wp-calendar">
1482 <caption>' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</caption>
1488 for ( $wdcount=0; $wdcount<=6; $wdcount++ ) {
1489 $myweek[] = $wp_locale->get_weekday(($wdcount+$week_begins)%7);
1492 foreach ( $myweek as $wd ) {
1493 $day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd);
1494 $wd = esc_attr($wd);
1495 $calendar_output .= "\n\t\t<th scope=\"col\" title=\"$wd\">$day_name</th>";
1498 $calendar_output .= '
1506 $calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a href="' . get_month_link($previous->year, $previous->month) . '">« ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>';
1508 $calendar_output .= "\n\t\t".'<td colspan="3" id="prev" class="pad"> </td>';
1511 $calendar_output .= "\n\t\t".'<td class="pad"> </td>';
1514 $calendar_output .= "\n\t\t".'<td colspan="3" id="next"><a href="' . get_month_link($next->year, $next->month) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' »</a></td>';
1516 $calendar_output .= "\n\t\t".'<td colspan="3" id="next" class="pad"> </td>';
1519 $calendar_output .= '
1526 // Get days with posts
1527 $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
1528 FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00'
1529 AND post_type = 'post' AND post_status = 'publish'
1530 AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N);
1531 if ( $dayswithposts ) {
1532 foreach ( (array) $dayswithposts as $daywith ) {
1533 $daywithpost[] = $daywith[0];
1536 $daywithpost = array();
1539 if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'camino') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false)
1540 $ak_title_separator = "\n";
1542 $ak_title_separator = ', ';
1544 $ak_titles_for_day = array();
1545 $ak_post_titles = $wpdb->get_results("SELECT ID, post_title, DAYOFMONTH(post_date) as dom "
1546 ."FROM $wpdb->posts "
1547 ."WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' "
1548 ."AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59' "
1549 ."AND post_type = 'post' AND post_status = 'publish'"
1551 if ( $ak_post_titles ) {
1552 foreach ( (array) $ak_post_titles as $ak_post_title ) {
1554 /** This filter is documented in wp-includes/post-template.php */
1555 $post_title = esc_attr( apply_filters( 'the_title', $ak_post_title->post_title, $ak_post_title->ID ) );
1557 if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) )
1558 $ak_titles_for_day['day_'.$ak_post_title->dom] = '';
1559 if ( empty($ak_titles_for_day["$ak_post_title->dom"]) ) // first one
1560 $ak_titles_for_day["$ak_post_title->dom"] = $post_title;
1562 $ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . $post_title;
1566 // See how much we should pad in the beginning
1567 $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins);
1569 $calendar_output .= "\n\t\t".'<td colspan="'. esc_attr($pad) .'" class="pad"> </td>';
1571 $daysinmonth = intval(date('t', $unixmonth));
1572 for ( $day = 1; $day <= $daysinmonth; ++$day ) {
1573 if ( isset($newrow) && $newrow )
1574 $calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t";
1577 if ( $day == gmdate('j', current_time('timestamp')) && $thismonth == gmdate('m', current_time('timestamp')) && $thisyear == gmdate('Y', current_time('timestamp')) )
1578 $calendar_output .= '<td id="today">';
1580 $calendar_output .= '<td>';
1582 if ( in_array($day, $daywithpost) ) // any posts today?
1583 $calendar_output .= '<a href="' . get_day_link( $thisyear, $thismonth, $day ) . '" title="' . esc_attr( $ak_titles_for_day[ $day ] ) . "\">$day</a>";
1585 $calendar_output .= $day;
1586 $calendar_output .= '</td>';
1588 if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) )
1592 $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins);
1593 if ( $pad != 0 && $pad != 7 )
1594 $calendar_output .= "\n\t\t".'<td class="pad" colspan="'. esc_attr($pad) .'"> </td>';
1596 $calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>";
1598 $cache[ $key ] = $calendar_output;
1599 wp_cache_set( 'get_calendar', $cache, 'calendar' );
1603 * Filter the HTML calendar output.
1607 * @param string $calendar_output HTML output of the calendar.
1609 echo apply_filters( 'get_calendar', $calendar_output );
1611 /** This filter is documented in wp-includes/general-template.php */
1612 return apply_filters( 'get_calendar', $calendar_output );
1618 * Purge the cached results of get_calendar.
1623 function delete_get_calendar_cache() {
1624 wp_cache_delete( 'get_calendar', 'calendar' );
1626 add_action( 'save_post', 'delete_get_calendar_cache' );
1627 add_action( 'delete_post', 'delete_get_calendar_cache' );
1628 add_action( 'update_option_start_of_week', 'delete_get_calendar_cache' );
1629 add_action( 'update_option_gmt_offset', 'delete_get_calendar_cache' );
1632 * Display all of the allowed tags in HTML format with attributes.
1634 * This is useful for displaying in the comment area, which elements and
1635 * attributes are supported. As well as any plugins which want to display it.
1638 * @uses $allowedtags
1640 * @return string HTML allowed tags entity encoded.
1642 function allowed_tags() {
1643 global $allowedtags;
1645 foreach ( (array) $allowedtags as $tag => $attributes ) {
1646 $allowed .= '<'.$tag;
1647 if ( 0 < count($attributes) ) {
1648 foreach ( $attributes as $attribute => $limits ) {
1649 $allowed .= ' '.$attribute.'=""';
1654 return htmlentities($allowed);
1657 /***** Date/Time tags *****/
1660 * Outputs the date in iso8601 format for xml files.
1664 function the_date_xml() {
1665 echo mysql2date( 'Y-m-d', get_post()->post_date, false );
1669 * Display or Retrieve the date the current post was written (once per date)
1671 * Will only output the date if the current post's date is different from the
1672 * previous one output.
1674 * i.e. Only one date listing will show per day worth of posts shown in the loop, even if the
1675 * function is called several times for each post.
1677 * HTML output can be filtered with 'the_date'.
1678 * Date string output can be filtered with 'get_the_date'.
1682 * @uses get_the_date()
1683 * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
1684 * @param string $before Optional. Output before the date.
1685 * @param string $after Optional. Output after the date.
1686 * @param bool $echo Optional, default is display. Whether to echo the date or return it.
1687 * @return string|null Null if displaying, string if retrieving.
1689 function the_date( $d = '', $before = '', $after = '', $echo = true ) {
1690 global $currentday, $previousday;
1692 if ( $currentday != $previousday ) {
1693 $the_date = $before . get_the_date( $d ) . $after;
1694 $previousday = $currentday;
1697 * Filter the date a post was published for display.
1701 * @param string $the_date The formatted date string.
1702 * @param string $d PHP date format. Defaults to 'date_format' option
1704 * @param string $before HTML output before the date.
1705 * @param string $after HTML output after the date.
1707 $the_date = apply_filters( 'the_date', $the_date, $d, $before, $after );
1719 * Retrieve the date on which the post was written.
1721 * Unlike the_date() this function will always return the date.
1722 * Modify output with 'get_the_date' filter.
1726 * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
1727 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default current post.
1728 * @return string|bool Date the current post was written. False on failure.
1730 function get_the_date( $d = '', $post = null ) {
1731 $post = get_post( $post );
1738 $the_date = mysql2date( get_option( 'date_format' ), $post->post_date );
1740 $the_date = mysql2date( $d, $post->post_date );
1744 * Filter the date a post was published.
1748 * @param string $the_date The formatted date.
1749 * @param string $d PHP date format. Defaults to 'date_format' option
1751 * @param int|WP_Post $post The post object or ID.
1753 return apply_filters( 'get_the_date', $the_date, $d, $post );
1757 * Display the date on which the post was last modified.
1761 * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
1762 * @param string $before Optional. Output before the date.
1763 * @param string $after Optional. Output after the date.
1764 * @param bool $echo Optional, default is display. Whether to echo the date or return it.
1765 * @return string|null Null if displaying, string if retrieving.
1767 function the_modified_date($d = '', $before='', $after='', $echo = true) {
1769 $the_modified_date = $before . get_the_modified_date($d) . $after;
1772 * Filter the date a post was last modified for display.
1776 * @param string $the_modified_date The last modified date.
1777 * @param string $d PHP date format. Defaults to 'date_format' option
1779 * @param string $before HTML output before the date.
1780 * @param string $after HTML output after the date.
1782 $the_modified_date = apply_filters( 'the_modified_date', $the_modified_date, $d, $before, $after );
1785 echo $the_modified_date;
1787 return $the_modified_date;
1792 * Retrieve the date on which the post was last modified.
1796 * @param string $d Optional. PHP date format. Defaults to the "date_format" option
1799 function get_the_modified_date($d = '') {
1801 $the_time = get_post_modified_time(get_option('date_format'), null, null, true);
1803 $the_time = get_post_modified_time($d, null, null, true);
1806 * Filter the date a post was last modified.
1810 * @param string $the_time The formatted date.
1811 * @param string $d PHP date format. Defaults to value specified in
1812 * 'date_format' option.
1814 return apply_filters( 'get_the_modified_date', $the_time, $d );
1818 * Display the time at which the post was written.
1822 * @param string $d Either 'G', 'U', or php date format.
1824 function the_time( $d = '' ) {
1826 * Filter the time a post was written for display.
1830 * @param string $get_the_time The formatted time.
1831 * @param string $d The time format. Accepts 'G', 'U',
1832 * or php date format.
1834 echo apply_filters( 'the_time', get_the_time( $d ), $d );
1838 * Retrieve the time at which the post was written.
1842 * @param string $d Optional. Format to use for retrieving the time the post
1843 * was written. Either 'G', 'U', or php date format defaults
1844 * to the value specified in the time_format option. Default empty.
1845 * @param int|WP_Post $post WP_Post object or ID. Default is global $post object.
1846 * @return string|int|bool Formatted date string or Unix timestamp. False on failure.
1848 function get_the_time( $d = '', $post = null ) {
1849 $post = get_post($post);
1856 $the_time = get_post_time(get_option('time_format'), false, $post, true);
1858 $the_time = get_post_time($d, false, $post, true);
1861 * Filter the time a post was written.
1865 * @param string $the_time The formatted time.
1866 * @param string $d Format to use for retrieving the time the post was written.
1867 * Accepts 'G', 'U', or php date format value specified
1868 * in 'time_format' option. Default empty.
1869 * @param int|WP_Post $post WP_Post object or ID.
1871 return apply_filters( 'get_the_time', $the_time, $d, $post );
1875 * Retrieve the time at which the post was written.
1879 * @param string $d Optional. Format to use for retrieving the time the post
1880 * was written. Either 'G', 'U', or php date format. Default 'U'.
1881 * @param bool $gmt Optional. Whether to retrieve the GMT time. Default false.
1882 * @param int|WP_Post $post WP_Post object or ID. Default is global $post object.
1883 * @param bool $translate Whether to translate the time string. Default false.
1884 * @return string|int|bool Formatted date string or Unix timestamp. False on failure.
1886 function get_post_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
1887 $post = get_post($post);
1894 $time = $post->post_date_gmt;
1896 $time = $post->post_date;
1898 $time = mysql2date($d, $time, $translate);
1901 * Filter the localized time a post was written.
1905 * @param string $time The formatted time.
1906 * @param string $d Format to use for retrieving the time the post was written.
1907 * Accepts 'G', 'U', or php date format. Default 'U'.
1908 * @param bool $gmt Whether to retrieve the GMT time. Default false.
1910 return apply_filters( 'get_post_time', $time, $d, $gmt );
1914 * Display the time at which the post was last modified.
1918 * @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
1920 function the_modified_time($d = '') {
1922 * Filter the localized time a post was last modified, for display.
1926 * @param string $get_the_modified_time The formatted time.
1927 * @param string $d The time format. Accepts 'G', 'U',
1928 * or php date format. Defaults to value
1929 * specified in 'time_format' option.
1931 echo apply_filters( 'the_modified_time', get_the_modified_time($d), $d );
1935 * Retrieve the time at which the post was last modified.
1939 * @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
1942 function get_the_modified_time($d = '') {
1944 $the_time = get_post_modified_time(get_option('time_format'), null, null, true);
1946 $the_time = get_post_modified_time($d, null, null, true);
1949 * Filter the localized time a post was last modified.
1953 * @param string $the_time The formatted time.
1954 * @param string $d Format to use for retrieving the time the post was
1955 * written. Accepts 'G', 'U', or php date format. Defaults
1956 * to value specified in 'time_format' option.
1958 return apply_filters( 'get_the_modified_time', $the_time, $d );
1962 * Retrieve the time at which the post was last modified.
1966 * @param string $d Optional. Format to use for retrieving the time the post
1967 * was modified. Either 'G', 'U', or php date format. Default 'U'.
1968 * @param bool $gmt Optional. Whether to retrieve the GMT time. Default false.
1969 * @param int|WP_Post $post WP_Post object or ID. Default is global $post object.
1970 * @param bool $translate Whether to translate the time string. Default false.
1971 * @return string|int|bool Formatted date string or Unix timestamp. False on failure.
1973 function get_post_modified_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
1974 $post = get_post($post);
1981 $time = $post->post_modified_gmt;
1983 $time = $post->post_modified;
1984 $time = mysql2date($d, $time, $translate);
1987 * Filter the localized time a post was last modified.
1991 * @param string $time The formatted time.
1992 * @param string $d The date format. Accepts 'G', 'U', or php date format. Default 'U'.
1993 * @param bool $gmt Whether to return the GMT time. Default false.
1995 return apply_filters( 'get_post_modified_time', $time, $d, $gmt );
1999 * Display the weekday on which the post was written.
2005 function the_weekday() {
2007 $the_weekday = $wp_locale->get_weekday( mysql2date( 'w', get_post()->post_date, false ) );
2010 * Filter the weekday on which the post was written, for display.
2014 * @param string $the_weekday
2016 $the_weekday = apply_filters( 'the_weekday', $the_weekday );
2021 * Display the weekday on which the post was written.
2023 * Will only output the weekday if the current post's weekday is different from
2024 * the previous one output.
2028 * @param string $before Optional Output before the date.
2029 * @param string $after Optional Output after the date.
2031 function the_weekday_date($before='',$after='') {
2032 global $wp_locale, $currentday, $previousweekday;
2033 $the_weekday_date = '';
2034 if ( $currentday != $previousweekday ) {
2035 $the_weekday_date .= $before;
2036 $the_weekday_date .= $wp_locale->get_weekday( mysql2date( 'w', get_post()->post_date, false ) );
2037 $the_weekday_date .= $after;
2038 $previousweekday = $currentday;
2042 * Filter the localized date on which the post was written, for display.
2046 * @param string $the_weekday_date
2047 * @param string $before The HTML to output before the date.
2048 * @param string $after The HTML to output after the date.
2050 $the_weekday_date = apply_filters( 'the_weekday_date', $the_weekday_date, $before, $after );
2051 echo $the_weekday_date;
2055 * Fire the wp_head action
2059 function wp_head() {
2061 * Print scripts or data in the head tag on the front end.
2065 do_action( 'wp_head' );
2069 * Fire the wp_footer action
2073 function wp_footer() {
2075 * Print scripts or data before the closing body tag on the front end.
2079 do_action( 'wp_footer' );
2083 * Display the links to the general feeds.
2087 * @param array $args Optional arguments.
2089 function feed_links( $args = array() ) {
2090 if ( !current_theme_supports('automatic-feed-links') )
2094 /* translators: Separator between blog name and feed type in feed links */
2095 'separator' => _x('»', 'feed link'),
2096 /* translators: 1: blog title, 2: separator (raquo) */
2097 'feedtitle' => __('%1$s %2$s Feed'),
2098 /* translators: 1: blog title, 2: separator (raquo) */
2099 'comstitle' => __('%1$s %2$s Comments Feed'),
2102 $args = wp_parse_args( $args, $defaults );
2104 echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( sprintf( $args['feedtitle'], get_bloginfo('name'), $args['separator'] ) ) . '" href="' . esc_url( get_feed_link() ) . "\" />\n";
2105 echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( sprintf( $args['comstitle'], get_bloginfo('name'), $args['separator'] ) ) . '" href="' . esc_url( get_feed_link( 'comments_' . get_default_feed() ) ) . "\" />\n";
2109 * Display the links to the extra feeds such as category feeds.
2113 * @param array $args Optional arguments.
2115 function feed_links_extra( $args = array() ) {
2117 /* translators: Separator between blog name and feed type in feed links */
2118 'separator' => _x('»', 'feed link'),
2119 /* translators: 1: blog name, 2: separator(raquo), 3: post title */
2120 'singletitle' => __('%1$s %2$s %3$s Comments Feed'),
2121 /* translators: 1: blog name, 2: separator(raquo), 3: category name */
2122 'cattitle' => __('%1$s %2$s %3$s Category Feed'),
2123 /* translators: 1: blog name, 2: separator(raquo), 3: tag name */
2124 'tagtitle' => __('%1$s %2$s %3$s Tag Feed'),
2125 /* translators: 1: blog name, 2: separator(raquo), 3: author name */
2126 'authortitle' => __('%1$s %2$s Posts by %3$s Feed'),
2127 /* translators: 1: blog name, 2: separator(raquo), 3: search phrase */
2128 'searchtitle' => __('%1$s %2$s Search Results for “%3$s” Feed'),
2129 /* translators: 1: blog name, 2: separator(raquo), 3: post type name */
2130 'posttypetitle' => __('%1$s %2$s %3$s Feed'),
2133 $args = wp_parse_args( $args, $defaults );
2135 if ( is_singular() ) {
2137 $post = get_post( $id );
2139 if ( comments_open() || pings_open() || $post->comment_count > 0 ) {
2140 $title = sprintf( $args['singletitle'], get_bloginfo('name'), $args['separator'], the_title_attribute( array( 'echo' => false ) ) );
2141 $href = get_post_comments_feed_link( $post->ID );
2143 } elseif ( is_post_type_archive() ) {
2144 $post_type = get_query_var( 'post_type' );
2145 if ( is_array( $post_type ) )
2146 $post_type = reset( $post_type );
2148 $post_type_obj = get_post_type_object( $post_type );
2149 $title = sprintf( $args['posttypetitle'], get_bloginfo( 'name' ), $args['separator'], $post_type_obj->labels->name );
2150 $href = get_post_type_archive_feed_link( $post_type_obj->name );
2151 } elseif ( is_category() ) {
2152 $term = get_queried_object();
2155 $title = sprintf( $args['cattitle'], get_bloginfo('name'), $args['separator'], $term->name );
2156 $href = get_category_feed_link( $term->term_id );
2158 } elseif ( is_tag() ) {
2159 $term = get_queried_object();
2162 $title = sprintf( $args['tagtitle'], get_bloginfo('name'), $args['separator'], $term->name );
2163 $href = get_tag_feed_link( $term->term_id );
2165 } elseif ( is_author() ) {
2166 $author_id = intval( get_query_var('author') );
2168 $title = sprintf( $args['authortitle'], get_bloginfo('name'), $args['separator'], get_the_author_meta( 'display_name', $author_id ) );
2169 $href = get_author_feed_link( $author_id );
2170 } elseif ( is_search() ) {
2171 $title = sprintf( $args['searchtitle'], get_bloginfo('name'), $args['separator'], get_search_query( false ) );
2172 $href = get_search_feed_link();
2173 } elseif ( is_post_type_archive() ) {
2174 $title = sprintf( $args['posttypetitle'], get_bloginfo('name'), $args['separator'], post_type_archive_title( '', false ) );
2175 $post_type_obj = get_queried_object();
2176 if ( $post_type_obj )
2177 $href = get_post_type_archive_feed_link( $post_type_obj->name );
2180 if ( isset($title) && isset($href) )
2181 echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( $title ) . '" href="' . esc_url( $href ) . '" />' . "\n";
2185 * Display the link to the Really Simple Discovery service endpoint.
2187 * @link http://archipelago.phrasewise.com/rsd
2190 function rsd_link() {
2191 echo '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . get_bloginfo('wpurl') . "/xmlrpc.php?rsd\" />\n";
2195 * Display the link to the Windows Live Writer manifest file.
2197 * @link http://msdn.microsoft.com/en-us/library/bb463265.aspx
2200 function wlwmanifest_link() {
2201 echo '<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="',
2202 includes_url( 'wlwmanifest.xml' ), '" /> ', "\n";
2206 * Display a noindex meta tag if required by the blog configuration.
2208 * If a blog is marked as not being public then the noindex meta tag will be
2209 * output to tell web robots not to index the page content. Add this to the wp_head action.
2210 * Typical usage is as a wp_head callback. add_action( 'wp_head', 'noindex' );
2216 function noindex() {
2217 // If the blog is not public, tell robots to go away.
2218 if ( '0' == get_option('blog_public') )
2223 * Display a noindex meta tag.
2225 * Outputs a noindex meta tag that tells web robots not to index the page content.
2226 * Typical usage is as a wp_head callback. add_action( 'wp_head', 'wp_no_robots' );
2230 function wp_no_robots() {
2231 echo "<meta name='robots' content='noindex,follow' />\n";
2235 * Whether the user should have a WYSIWIG editor.
2237 * Checks that the user requires a WYSIWIG editor and that the editor is
2238 * supported in the users browser.
2244 function user_can_richedit() {
2245 global $wp_rich_edit, $is_gecko, $is_opera, $is_safari, $is_chrome, $is_IE;
2247 if ( !isset($wp_rich_edit) ) {
2248 $wp_rich_edit = false;
2250 if ( get_user_option( 'rich_editing' ) == 'true' || ! is_user_logged_in() ) { // default to 'true' for logged out users
2252 $wp_rich_edit = ! wp_is_mobile() || ( preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match ) && intval( $match[1] ) >= 534 );
2253 } elseif ( $is_gecko || $is_chrome || $is_IE || ( $is_opera && !wp_is_mobile() ) ) {
2254 $wp_rich_edit = true;
2260 * Filter whether the user can access the rich (Visual) editor.
2264 * @param bool $wp_rich_edit Whether the user can access to the rich (Visual) editor.
2266 return apply_filters( 'user_can_richedit', $wp_rich_edit );
2270 * Find out which editor should be displayed by default.
2272 * Works out which of the two editors to display as the current editor for a
2273 * user. The 'html' setting is for the "Text" editor tab.
2277 * @return string Either 'tinymce', or 'html', or 'test'
2279 function wp_default_editor() {
2280 $r = user_can_richedit() ? 'tinymce' : 'html'; // defaults
2281 if ( wp_get_current_user() ) { // look for cookie
2282 $ed = get_user_setting('editor', 'tinymce');
2283 $r = ( in_array($ed, array('tinymce', 'html', 'test') ) ) ? $ed : $r;
2287 * Filter which editor should be displayed by default.
2291 * @param array $r An array of editors. Accepts 'tinymce', 'html', 'test'.
2293 return apply_filters( 'wp_default_editor', $r );
2297 * Renders an editor.
2299 * Using this function is the proper way to output all needed components for both TinyMCE and Quicktags.
2300 * _WP_Editors should not be used directly. See http://core.trac.wordpress.org/ticket/17144.
2302 * NOTE: Once initialized the TinyMCE editor cannot be safely moved in the DOM. For that reason
2303 * running wp_editor() inside of a metabox is not a good idea unless only Quicktags is used.
2304 * On the post edit screen several actions can be used to include additional editors
2305 * containing TinyMCE: 'edit_page_form', 'edit_form_advanced' and 'dbx_post_sidebar'.
2306 * See http://core.trac.wordpress.org/ticket/19173 for more information.
2308 * @see wp-includes/class-wp-editor.php
2311 * @param string $content Initial content for the editor.
2312 * @param string $editor_id HTML ID attribute value for the textarea and TinyMCE. Can only be /[a-z]+/.
2313 * @param array $settings See _WP_Editors::editor().
2315 function wp_editor( $content, $editor_id, $settings = array() ) {
2316 if ( ! class_exists( '_WP_Editors' ) )
2317 require( ABSPATH . WPINC . '/class-wp-editor.php' );
2319 _WP_Editors::editor($content, $editor_id, $settings);
2323 * Retrieve the contents of the search WordPress query variable.
2325 * The search query string is passed through {@link esc_attr()}
2326 * to ensure that it is safe for placing in an html attribute.
2331 * @param bool $escaped Whether the result is escaped. Default true.
2332 * Only use when you are later escaping it. Do not use unescaped.
2335 function get_search_query( $escaped = true ) {
2337 * Filter the contents of the search query variable.
2341 * @param mixed $search Contents of the search query variable.
2343 $query = apply_filters( 'get_search_query', get_query_var( 's' ) );
2346 $query = esc_attr( $query );
2351 * Display the contents of the search query variable.
2353 * The search query string is passed through {@link esc_attr()}
2354 * to ensure that it is safe for placing in an html attribute.
2359 function the_search_query() {
2361 * Filter the contents of the search query variable for display.
2365 * @param mixed $search Contents of the search query variable.
2367 echo esc_attr( apply_filters( 'the_search_query', get_search_query( false ) ) );
2371 * Display the language attributes for the html tag.
2373 * Builds up a set of html attributes containing the text direction and language
2374 * information for the page.
2378 * @param string $doctype The type of html document (xhtml|html).
2380 function language_attributes($doctype = 'html') {
2381 $attributes = array();
2383 if ( function_exists( 'is_rtl' ) && is_rtl() )
2384 $attributes[] = 'dir="rtl"';
2386 if ( $lang = get_bloginfo('language') ) {
2387 if ( get_option('html_type') == 'text/html' || $doctype == 'html' )
2388 $attributes[] = "lang=\"$lang\"";
2390 if ( get_option('html_type') != 'text/html' || $doctype == 'xhtml' )
2391 $attributes[] = "xml:lang=\"$lang\"";
2394 $output = implode(' ', $attributes);
2397 * Filter the language attributes for display in the html tag.
2401 * @param string $output A space-separated list of language attributes.
2403 echo apply_filters( 'language_attributes', $output );
2407 * Retrieve paginated link for archive post pages.
2409 * Technically, the function can be used to create paginated link list for any
2410 * area. The 'base' argument is used to reference the url, which will be used to
2411 * create the paginated links. The 'format' argument is then used for replacing
2412 * the page number. It is however, most likely and by default, to be used on the
2413 * archive post pages.
2415 * The 'type' argument controls format of the returned value. The default is
2416 * 'plain', which is just a string with the links separated by a newline
2417 * character. The other possible values are either 'array' or 'list'. The
2418 * 'array' value will return an array of the paginated link list to offer full
2419 * control of display. The 'list' value will place all of the paginated links in
2420 * an unordered HTML list.
2422 * The 'total' argument is the total amount of pages and is an integer. The
2423 * 'current' argument is the current page number and is also an integer.
2425 * An example of the 'base' argument is "http://example.com/all_posts.php%_%"
2426 * and the '%_%' is required. The '%_%' will be replaced by the contents of in
2427 * the 'format' argument. An example for the 'format' argument is "?page=%#%"
2428 * and the '%#%' is also required. The '%#%' will be replaced with the page
2431 * You can include the previous and next links in the list by setting the
2432 * 'prev_next' argument to true, which it is by default. You can set the
2433 * previous text, by using the 'prev_text' argument. You can set the next text
2434 * by setting the 'next_text' argument.
2436 * If the 'show_all' argument is set to true, then it will show all of the pages
2437 * instead of a short list of the pages near the current page. By default, the
2438 * 'show_all' is set to false and controlled by the 'end_size' and 'mid_size'
2439 * arguments. The 'end_size' argument is how many numbers on either the start
2440 * and the end list edges, by default is 1. The 'mid_size' argument is how many
2441 * numbers to either side of current page, but not including current page.
2443 * It is possible to add query vars to the link by using the 'add_args' argument
2444 * and see {@link add_query_arg()} for more information.
2446 * The 'before_page_number' and 'after_page_number' arguments allow users to
2447 * augment the links themselves. Typically this might be to add context to the
2448 * numbered links so that screen reader users understand what the links are for.
2449 * The text strings are added before and after the page number - within the
2454 * @param string|array $args Optional. Override defaults.
2455 * @return array|string String of page links or array of page links.
2457 function paginate_links( $args = '' ) {
2458 global $wp_query, $wp_rewrite;
2460 $total = ( isset( $wp_query->max_num_pages ) ) ? $wp_query->max_num_pages : 1;
2461 $current = ( get_query_var( 'paged' ) ) ? intval( get_query_var( 'paged' ) ) : 1;
2462 $pagenum_link = html_entity_decode( get_pagenum_link() );
2463 $query_args = array();
2464 $url_parts = explode( '?', $pagenum_link );
2466 if ( isset( $url_parts[1] ) ) {
2467 wp_parse_str( $url_parts[1], $query_args );
2470 $pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link );
2471 $pagenum_link = trailingslashit( $pagenum_link ) . '%_%';
2473 $format = $wp_rewrite->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
2474 $format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%';
2477 'base' => $pagenum_link, // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
2478 'format' => $format, // ?page=%#% : %#% is replaced by the page number
2480 'current' => $current,
2481 'show_all' => false,
2482 'prev_next' => true,
2483 'prev_text' => __('« Previous'),
2484 'next_text' => __('Next »'),
2488 'add_args' => false, // array of query args to add
2489 'add_fragment' => '',
2490 'before_page_number' => '',
2491 'after_page_number' => ''
2494 $args = wp_parse_args( $args, $defaults );
2496 // Who knows what else people pass in $args
2497 $total = (int) $args['total'];
2501 $current = (int) $args['current'];
2502 $end_size = (int) $args['end_size']; // Out of bounds? Make it the default.
2503 if ( $end_size < 1 ) {
2506 $mid_size = (int) $args['mid_size'];
2507 if ( $mid_size < 0 ) {
2510 $add_args = is_array( $args['add_args'] ) ? $args['add_args'] : false;
2512 $page_links = array();
2515 if ( $args['prev_next'] && $current && 1 < $current ) :
2516 $link = str_replace( '%_%', 2 == $current ? '' : $args['format'], $args['base'] );
2517 $link = str_replace( '%#%', $current - 1, $link );
2519 $link = add_query_arg( $add_args, $link );
2520 $link .= $args['add_fragment'];
2523 * Filter the paginated links for the given archive pages.
2527 * @param string $link The paginated link URL.
2529 $page_links[] = '<a class="prev page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $args['prev_text'] . '</a>';
2531 for ( $n = 1; $n <= $total; $n++ ) :
2532 if ( $n == $current ) :
2533 $page_links[] = "<span class='page-numbers current'>" . $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] . "</span>";
2536 if ( $args['show_all'] || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
2537 $link = str_replace( '%_%', 1 == $n ? '' : $args['format'], $args['base'] );
2538 $link = str_replace( '%#%', $n, $link );
2540 $link = add_query_arg( $add_args, $link );
2541 $link .= $args['add_fragment'];
2543 /** This filter is documented in wp-includes/general-template.php */
2544 $page_links[] = "<a class='page-numbers' href='" . esc_url( apply_filters( 'paginate_links', $link ) ) . "'>" . $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] . "</a>";
2546 elseif ( $dots && ! $args['show_all'] ) :
2547 $page_links[] = '<span class="page-numbers dots">' . __( '…' ) . '</span>';
2552 if ( $args['prev_next'] && $current && ( $current < $total || -1 == $total ) ) :
2553 $link = str_replace( '%_%', $args['format'], $args['base'] );
2554 $link = str_replace( '%#%', $current + 1, $link );
2556 $link = add_query_arg( $add_args, $link );
2557 $link .= $args['add_fragment'];
2559 /** This filter is documented in wp-includes/general-template.php */
2560 $page_links[] = '<a class="next page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $args['next_text'] . '</a>';
2562 switch ( $args['type'] ) {
2567 $r .= "<ul class='page-numbers'>\n\t<li>";
2568 $r .= join("</li>\n\t<li>", $page_links);
2569 $r .= "</li>\n</ul>\n";
2573 $r = join("\n", $page_links);
2580 * Registers an admin colour scheme css file.
2582 * Allows a plugin to register a new admin colour scheme. For example:
2584 * wp_admin_css_color('classic', __('Classic'), admin_url("css/colors-classic.css"),
2585 * array('#07273E', '#14568A', '#D54E21', '#2683AE'));
2590 * @param string $key The unique key for this theme.
2591 * @param string $name The name of the theme.
2592 * @param string $url The url of the css file containing the colour scheme.
2593 * @param array $colors Optional An array of CSS color definitions which are used to give the user a feel for the theme.
2594 * @param array $icons Optional An array of CSS color definitions used to color any SVG icons
2596 function wp_admin_css_color( $key, $name, $url, $colors = array(), $icons = array() ) {
2597 global $_wp_admin_css_colors;
2599 if ( !isset($_wp_admin_css_colors) )
2600 $_wp_admin_css_colors = array();
2602 $_wp_admin_css_colors[$key] = (object) array(
2605 'colors' => $colors,
2606 'icon_colors' => $icons,
2611 * Registers the default Admin color schemes
2615 function register_admin_color_schemes() {
2616 $suffix = is_rtl() ? '-rtl' : '';
2617 $suffix .= defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
2619 wp_admin_css_color( 'fresh', _x( 'Default', 'admin color scheme' ),
2621 array( '#222', '#333', '#0074a2', '#2ea2cc' ),
2622 array( 'base' => '#999', 'focus' => '#2ea2cc', 'current' => '#fff' )
2625 // Other color schemes are not available when running out of src
2626 if ( false !== strpos( $GLOBALS['wp_version'], '-src' ) )
2629 wp_admin_css_color( 'light', _x( 'Light', 'admin color scheme' ),
2630 admin_url( "css/colors/light/colors$suffix.css" ),
2631 array( '#e5e5e5', '#999', '#d64e07', '#04a4cc' ),
2632 array( 'base' => '#999', 'focus' => '#ccc', 'current' => '#ccc' )
2635 wp_admin_css_color( 'blue', _x( 'Blue', 'admin color scheme' ),
2636 admin_url( "css/colors/blue/colors$suffix.css" ),
2637 array( '#096484', '#4796b3', '#52accc', '#74B6CE' ),
2638 array( 'base' => '#e5f8ff', 'focus' => '#fff', 'current' => '#fff' )
2641 wp_admin_css_color( 'midnight', _x( 'Midnight', 'admin color scheme' ),
2642 admin_url( "css/colors/midnight/colors$suffix.css" ),
2643 array( '#25282b', '#363b3f', '#69a8bb', '#e14d43' ),
2644 array( 'base' => '#f1f2f3', 'focus' => '#fff', 'current' => '#fff' )
2647 wp_admin_css_color( 'sunrise', _x( 'Sunrise', 'admin color scheme' ),
2648 admin_url( "css/colors/sunrise/colors$suffix.css" ),
2649 array( '#b43c38', '#cf4944', '#dd823b', '#ccaf0b' ),
2650 array( 'base' => '#f3f1f1', 'focus' => '#fff', 'current' => '#fff' )
2653 wp_admin_css_color( 'ectoplasm', _x( 'Ectoplasm', 'admin color scheme' ),
2654 admin_url( "css/colors/ectoplasm/colors$suffix.css" ),
2655 array( '#413256', '#523f6d', '#a3b745', '#d46f15' ),
2656 array( 'base' => '#ece6f6', 'focus' => '#fff', 'current' => '#fff' )
2659 wp_admin_css_color( 'ocean', _x( 'Ocean', 'admin color scheme' ),
2660 admin_url( "css/colors/ocean/colors$suffix.css" ),
2661 array( '#627c83', '#738e96', '#9ebaa0', '#aa9d88' ),
2662 array( 'base' => '#f2fcff', 'focus' => '#fff', 'current' => '#fff' )
2665 wp_admin_css_color( 'coffee', _x( 'Coffee', 'admin color scheme' ),
2666 admin_url( "css/colors/coffee/colors$suffix.css" ),
2667 array( '#46403c', '#59524c', '#c7a589', '#9ea476' ),
2668 array( 'base' => '#f3f2f1', 'focus' => '#fff', 'current' => '#fff' )
2674 * Display the URL of a WordPress admin CSS file.
2676 * @see WP_Styles::_css_href and its style_loader_src filter.
2680 * @param string $file file relative to wp-admin/ without its ".css" extension.
2682 function wp_admin_css_uri( $file = 'wp-admin' ) {
2683 if ( defined('WP_INSTALLING') ) {
2684 $_file = "./$file.css";
2686 $_file = admin_url("$file.css");
2688 $_file = add_query_arg( 'version', get_bloginfo( 'version' ), $_file );
2691 * Filter the URI of a WordPress admin CSS file.
2695 * @param string $_file Relative path to the file with query arguments attached.
2696 * @param string $file Relative path to the file, minus its ".css" extension.
2698 return apply_filters( 'wp_admin_css_uri', $_file, $file );
2702 * Enqueues or directly prints a stylesheet link to the specified CSS file.
2704 * "Intelligently" decides to enqueue or to print the CSS file. If the
2705 * 'wp_print_styles' action has *not* yet been called, the CSS file will be
2706 * enqueued. If the wp_print_styles action *has* been called, the CSS link will
2707 * be printed. Printing may be forced by passing true as the $force_echo
2708 * (second) parameter.
2710 * For backward compatibility with WordPress 2.3 calling method: If the $file
2711 * (first) parameter does not correspond to a registered CSS file, we assume
2712 * $file is a file relative to wp-admin/ without its ".css" extension. A
2713 * stylesheet link to that generated URL is printed.
2716 * @uses $wp_styles WordPress Styles Object
2718 * @param string $file Optional. Style handle name or file name (without ".css" extension) relative
2719 * to wp-admin/. Defaults to 'wp-admin'.
2720 * @param bool $force_echo Optional. Force the stylesheet link to be printed rather than enqueued.
2722 function wp_admin_css( $file = 'wp-admin', $force_echo = false ) {
2724 if ( !is_a($wp_styles, 'WP_Styles') )
2725 $wp_styles = new WP_Styles();
2727 // For backward compatibility
2728 $handle = 0 === strpos( $file, 'css/' ) ? substr( $file, 4 ) : $file;
2730 if ( $wp_styles->query( $handle ) ) {
2731 if ( $force_echo || did_action( 'wp_print_styles' ) ) // we already printed the style queue. Print this one immediately
2732 wp_print_styles( $handle );
2733 else // Add to style queue
2734 wp_enqueue_style( $handle );
2739 * Filter the stylesheet link to the specified CSS file.
2741 * If the site is set to display right-to-left, the RTL stylesheet link
2742 * will be used instead.
2746 * @param string $file Style handle name or filename (without ".css" extension)
2747 * relative to wp-admin/. Defaults to 'wp-admin'.
2749 echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( $file ) ) . "' type='text/css' />\n", $file );
2751 if ( function_exists( 'is_rtl' ) && is_rtl() ) {
2752 /** This filter is documented in wp-includes/general-template.php */
2753 echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( "$file-rtl" ) ) . "' type='text/css' />\n", "$file-rtl" );
2758 * Enqueues the default ThickBox js and css.
2760 * If any of the settings need to be changed, this can be done with another js
2761 * file similar to media-upload.js. That file should
2762 * require array('thickbox') to ensure it is loaded after.
2766 function add_thickbox() {
2767 wp_enqueue_script( 'thickbox' );
2768 wp_enqueue_style( 'thickbox' );
2770 if ( is_network_admin() )
2771 add_action( 'admin_head', '_thickbox_path_admin_subfolder' );
2775 * Display the XHTML generator that is generated on the wp_head hook.
2779 function wp_generator() {
2781 * Filter the output of the XHTML generator tag.
2785 * @param string $generator_type The XHTML generator.
2787 the_generator( apply_filters( 'wp_generator_type', 'xhtml' ) );
2791 * Display the generator XML or Comment for RSS, ATOM, etc.
2793 * Returns the correct generator type for the requested output format. Allows
2794 * for a plugin to filter generators overall the the_generator filter.
2798 * @param string $type The type of generator to output - (html|xhtml|atom|rss2|rdf|comment|export).
2800 function the_generator( $type ) {
2802 * Filter the output of the XHTML generator tag for display.
2806 * @param string $generator_type The generator output.
2807 * @param string $type The type of generator to output. Accepts 'html',
2808 * 'xhtml', 'atom', 'rss2', 'rdf', 'comment', 'export'.
2810 echo apply_filters( 'the_generator', get_the_generator($type), $type ) . "\n";
2814 * Creates the generator XML or Comment for RSS, ATOM, etc.
2816 * Returns the correct generator type for the requested output format. Allows
2817 * for a plugin to filter generators on an individual basis using the
2818 * 'get_the_generator_{$type}' filter.
2822 * @param string $type The type of generator to return - (html|xhtml|atom|rss2|rdf|comment|export).
2823 * @return string The HTML content for the generator.
2825 function get_the_generator( $type = '' ) {
2826 if ( empty( $type ) ) {
2828 $current_filter = current_filter();
2829 if ( empty( $current_filter ) )
2832 switch ( $current_filter ) {
2834 case 'commentsrss2_head' :
2845 case 'comments_atom_head' :
2854 $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '">';
2857 $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '" />';
2860 $gen = '<generator uri="http://wordpress.org/" version="' . get_bloginfo_rss( 'version' ) . '">WordPress</generator>';
2863 $gen = '<generator>http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '</generator>';
2866 $gen = '<admin:generatorAgent rdf:resource="http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '" />';
2869 $gen = '<!-- generator="WordPress/' . get_bloginfo( 'version' ) . '" -->';
2872 $gen = '<!-- generator="WordPress/' . get_bloginfo_rss('version') . '" created="'. date('Y-m-d H:i') . '" -->';
2877 * Filter the HTML for the retrieved generator type.
2879 * The dynamic portion of the hook name, $type, refers to the generator type.
2883 * @param string $gen The HTML markup output to 'wp_head()'.
2884 * @param string $type The type of generator. Accepts 'html', 'xhtml', 'atom',
2885 * 'rss2', 'rdf', 'comment', 'export'.
2887 return apply_filters( "get_the_generator_{$type}", $gen, $type );
2891 * Outputs the html checked attribute.
2893 * Compares the first two arguments and if identical marks as checked
2897 * @param mixed $checked One of the values to compare
2898 * @param mixed $current (true) The other value to compare if not just true
2899 * @param bool $echo Whether to echo or just return the string
2900 * @return string html attribute or empty string
2902 function checked( $checked, $current = true, $echo = true ) {
2903 return __checked_selected_helper( $checked, $current, $echo, 'checked' );
2907 * Outputs the html selected attribute.
2909 * Compares the first two arguments and if identical marks as selected
2913 * @param mixed $selected One of the values to compare
2914 * @param mixed $current (true) The other value to compare if not just true
2915 * @param bool $echo Whether to echo or just return the string
2916 * @return string html attribute or empty string
2918 function selected( $selected, $current = true, $echo = true ) {
2919 return __checked_selected_helper( $selected, $current, $echo, 'selected' );
2923 * Outputs the html disabled attribute.
2925 * Compares the first two arguments and if identical marks as disabled
2929 * @param mixed $disabled One of the values to compare
2930 * @param mixed $current (true) The other value to compare if not just true
2931 * @param bool $echo Whether to echo or just return the string
2932 * @return string html attribute or empty string
2934 function disabled( $disabled, $current = true, $echo = true ) {
2935 return __checked_selected_helper( $disabled, $current, $echo, 'disabled' );
2939 * Private helper function for checked, selected, and disabled.
2941 * Compares the first two arguments and if identical marks as $type
2946 * @param mixed $helper One of the values to compare
2947 * @param mixed $current (true) The other value to compare if not just true
2948 * @param bool $echo Whether to echo or just return the string
2949 * @param string $type The type of checked|selected|disabled we are doing
2950 * @return string html attribute or empty string
2952 function __checked_selected_helper( $helper, $current, $echo, $type ) {
2953 if ( (string) $helper === (string) $current )
2954 $result = " $type='$type'";
2965 * Default settings for heartbeat
2967 * Outputs the nonce used in the heartbeat XHR
2971 * @param array $settings
2972 * @return array $settings
2974 function wp_heartbeat_settings( $settings ) {
2976 $settings['ajaxurl'] = admin_url( 'admin-ajax.php', 'relative' );
2978 if ( is_user_logged_in() )
2979 $settings['nonce'] = wp_create_nonce( 'heartbeat-nonce' );