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 * @param string $name The name of the specialised header.
22 function get_header( $name = null ) {
24 * Fires before the header template file is loaded.
26 * The hook allows a specific header template file to be used in place of the
27 * default header template file. If your file is called header-new.php,
28 * you would specify the filename in the hook as get_header( 'new' ).
31 * @since 2.8.0 $name parameter added.
33 * @param string $name Name of the specific header file to use.
35 do_action( 'get_header', $name );
38 $name = (string) $name;
40 $templates[] = "header-{$name}.php";
42 $templates[] = 'header.php';
44 // Backward compat code will be removed in a future release
45 if ('' == locate_template($templates, true))
46 load_template( ABSPATH . WPINC . '/theme-compat/header.php');
50 * Load footer template.
52 * Includes the footer template for a theme or if a name is specified then a
53 * specialised footer will be included.
55 * For the parameter, if the file is called "footer-special.php" then specify
60 * @param string $name The name of the specialised footer.
62 function get_footer( $name = null ) {
64 * Fires before the footer template file is loaded.
66 * The hook allows a specific footer template file to be used in place of the
67 * default footer template file. If your file is called footer-new.php,
68 * you would specify the filename in the hook as get_footer( 'new' ).
71 * @since 2.8.0 $name parameter added.
73 * @param string $name Name of the specific footer file to use.
75 do_action( 'get_footer', $name );
78 $name = (string) $name;
80 $templates[] = "footer-{$name}.php";
82 $templates[] = 'footer.php';
84 // Backward compat code will be removed in a future release
85 if ('' == locate_template($templates, true))
86 load_template( ABSPATH . WPINC . '/theme-compat/footer.php');
90 * Load sidebar template.
92 * Includes the sidebar template for a theme or if a name is specified then a
93 * specialised sidebar will be included.
95 * For the parameter, if the file is called "sidebar-special.php" then specify
100 * @param string $name The name of the specialised sidebar.
102 function get_sidebar( $name = null ) {
104 * Fires before the sidebar template file is loaded.
106 * The hook allows a specific sidebar template file to be used in place of the
107 * default sidebar template file. If your file is called sidebar-new.php,
108 * you would specify the filename in the hook as get_sidebar( 'new' ).
111 * @since 2.8.0 $name parameter added.
113 * @param string $name Name of the specific sidebar file to use.
115 do_action( 'get_sidebar', $name );
117 $templates = array();
118 $name = (string) $name;
120 $templates[] = "sidebar-{$name}.php";
122 $templates[] = 'sidebar.php';
124 // Backward compat code will be removed in a future release
125 if ('' == locate_template($templates, true))
126 load_template( ABSPATH . WPINC . '/theme-compat/sidebar.php');
130 * Load a template part into a template
132 * Makes it easy for a theme to reuse sections of code in a easy to overload way
135 * Includes the named template part for a theme or if a name is specified then a
136 * specialised part will be included. If the theme contains no {slug}.php file
137 * then no template will be included.
139 * The template is included using require, not require_once, so you may include the
140 * same template part multiple times.
142 * For the $name parameter, if the file is called "{slug}-special.php" then specify
147 * @param string $slug The slug name for the generic template.
148 * @param string $name The name of the specialised template.
150 function get_template_part( $slug, $name = null ) {
152 * Fires before the specified template part file is loaded.
154 * The dynamic portion of the hook name, `$slug`, refers to the slug name
155 * for the generic template part.
159 * @param string $slug The slug name for the generic template.
160 * @param string $name The name of the specialized template.
162 do_action( "get_template_part_{$slug}", $slug, $name );
164 $templates = array();
165 $name = (string) $name;
167 $templates[] = "{$slug}-{$name}.php";
169 $templates[] = "{$slug}.php";
171 locate_template($templates, true, false);
175 * Display search form.
177 * Will first attempt to locate the searchform.php file in either the child or
178 * the parent, then load it. If it doesn't exist, then the default search form
179 * will be displayed. The default search form is HTML, which will be displayed.
180 * There is a filter applied to the search form HTML in order to edit or replace
181 * it. The filter is 'get_search_form'.
183 * This function is primarily used by themes which want to hardcode the search
184 * form into the sidebar and also by the search widget in WordPress.
186 * There is also an action that is called whenever the function is run called,
187 * 'pre_get_search_form'. This can be useful for outputting JavaScript that the
188 * search relies on or various formatting that applies to the beginning of the
189 * search. To give a few examples of what it can be used for.
193 * @param bool $echo Default to echo and not return the form.
194 * @return string|void String when $echo is false.
196 function get_search_form( $echo = true ) {
198 * Fires before the search form is retrieved, at the start of get_search_form().
200 * @since 2.7.0 as 'get_search_form' action.
203 * @link https://core.trac.wordpress.org/ticket/19321
205 do_action( 'pre_get_search_form' );
207 $format = current_theme_supports( 'html5', 'search-form' ) ? 'html5' : 'xhtml';
210 * Filter the HTML format of the search form.
214 * @param string $format The type of markup to use in the search form.
215 * Accepts 'html5', 'xhtml'.
217 $format = apply_filters( 'search_form_format', $format );
219 $search_form_template = locate_template( 'searchform.php' );
220 if ( '' != $search_form_template ) {
222 require( $search_form_template );
223 $form = ob_get_clean();
225 if ( 'html5' == $format ) {
226 $form = '<form role="search" method="get" class="search-form" action="' . esc_url( home_url( '/' ) ) . '">
228 <span class="screen-reader-text">' . _x( 'Search for:', 'label' ) . '</span>
229 <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' ) . '" />
231 <input type="submit" class="search-submit" value="'. esc_attr_x( 'Search', 'submit button' ) .'" />
234 $form = '<form role="search" method="get" id="searchform" class="searchform" action="' . esc_url( home_url( '/' ) ) . '">
236 <label class="screen-reader-text" for="s">' . _x( 'Search for:', 'label' ) . '</label>
237 <input type="text" value="' . get_search_query() . '" name="s" id="s" />
238 <input type="submit" id="searchsubmit" value="'. esc_attr_x( 'Search', 'submit button' ) .'" />
245 * Filter the HTML output of the search form.
249 * @param string $form The search form HTML output.
251 $result = apply_filters( 'get_search_form', $form );
253 if ( null === $result )
263 * Display the Log In/Out link.
265 * Displays a link, which allows users to navigate to the Log In page to log in
266 * or log out depending on whether they are currently logged in.
270 * @param string $redirect Optional path to redirect to on login/logout.
271 * @param bool $echo Default to echo and not return the link.
272 * @return string|void String when retrieving.
274 function wp_loginout($redirect = '', $echo = true) {
275 if ( ! is_user_logged_in() )
276 $link = '<a href="' . esc_url( wp_login_url($redirect) ) . '">' . __('Log in') . '</a>';
278 $link = '<a href="' . esc_url( wp_logout_url($redirect) ) . '">' . __('Log out') . '</a>';
282 * Filter the HTML output for the Log In/Log Out link.
286 * @param string $link The HTML link content.
288 echo apply_filters( 'loginout', $link );
290 /** This filter is documented in wp-includes/general-template.php */
291 return apply_filters( 'loginout', $link );
296 * Returns the Log Out URL.
298 * Returns the URL that allows the user to log out of the site.
302 * @param string $redirect Path to redirect to on logout.
303 * @return string A log out URL.
305 function wp_logout_url($redirect = '') {
306 $args = array( 'action' => 'logout' );
307 if ( !empty($redirect) ) {
308 $args['redirect_to'] = urlencode( $redirect );
311 $logout_url = add_query_arg($args, site_url('wp-login.php', 'login'));
312 $logout_url = wp_nonce_url( $logout_url, 'log-out' );
315 * Filter the logout URL.
319 * @param string $logout_url The Log Out URL.
320 * @param string $redirect Path to redirect to on logout.
322 return apply_filters( 'logout_url', $logout_url, $redirect );
326 * Returns the URL that allows the user to log in to the site.
330 * @param string $redirect Path to redirect to on login.
331 * @param bool $force_reauth Whether to force reauthorization, even if a cookie is present. Default is false.
332 * @return string A log in URL.
334 function wp_login_url($redirect = '', $force_reauth = false) {
335 $login_url = site_url('wp-login.php', 'login');
337 if ( !empty($redirect) )
338 $login_url = add_query_arg('redirect_to', urlencode($redirect), $login_url);
341 $login_url = add_query_arg('reauth', '1', $login_url);
344 * Filter the login URL.
347 * @since 4.2.0 The `$force_reauth` parameter was added.
349 * @param string $login_url The login URL.
350 * @param string $redirect The path to redirect to on login, if supplied.
351 * @param bool $force_reauth Whether to force reauthorization, even if a cookie is present.
353 return apply_filters( 'login_url', $login_url, $redirect, $force_reauth );
357 * Returns the URL that allows the user to register on the site.
361 * @return string User registration URL.
363 function wp_registration_url() {
365 * Filter the user registration URL.
369 * @param string $register The user registration URL.
371 return apply_filters( 'register_url', site_url( 'wp-login.php?action=register', 'login' ) );
375 * Provides a simple login form for use anywhere within WordPress.
377 * The login format HTML is echoed by default. Pass a false value for `$echo` to return it instead.
381 * @param array $args {
382 * Optional. Array of options to control the form output. Default empty array.
384 * @type bool $echo Whether to display the login form or return the form HTML code.
385 * Default true (echo).
386 * @type string $redirect URL to redirect to. Must be absolute, as in "https://example.com/mypage/".
387 * Default is to redirect back to the request URI.
388 * @type string $form_id ID attribute value for the form. Default 'loginform'.
389 * @type string $label_username Label for the username field. Default 'Username'.
390 * @type string $label_password Label for the password field. Default 'Password'.
391 * @type string $label_remember Label for the remember field. Default 'Remember Me'.
392 * @type string $label_log_in Label for the submit button. Default 'Log In'.
393 * @type string $id_username ID attribute value for the username field. Default 'user_login'.
394 * @type string $id_password ID attribute value for the password field. Default 'user_pass'.
395 * @type string $id_remember ID attribute value for the remember field. Default 'rememberme'.
396 * @type string $id_submit ID attribute value for the submit button. Default 'wp-submit'.
397 * @type bool $remember Whether to display the "rememberme" checkbox in the form.
398 * @type string $value_username Default value for the username field. Default empty.
399 * @type bool $value_remember Whether the "Remember Me" checkbox should be checked by default.
400 * Default false (unchecked).
403 * @return string|void String when retrieving.
405 function wp_login_form( $args = array() ) {
408 // Default 'redirect' value takes the user back to the request URI.
409 'redirect' => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],
410 'form_id' => 'loginform',
411 'label_username' => __( 'Username' ),
412 'label_password' => __( 'Password' ),
413 'label_remember' => __( 'Remember Me' ),
414 'label_log_in' => __( 'Log In' ),
415 'id_username' => 'user_login',
416 'id_password' => 'user_pass',
417 'id_remember' => 'rememberme',
418 'id_submit' => 'wp-submit',
420 'value_username' => '',
421 // Set 'value_remember' to true to default the "Remember me" checkbox to checked.
422 'value_remember' => false,
426 * Filter the default login form output arguments.
430 * @see wp_login_form()
432 * @param array $defaults An array of default login form arguments.
434 $args = wp_parse_args( $args, apply_filters( 'login_form_defaults', $defaults ) );
437 * Filter content to display at the top of the login form.
439 * The filter evaluates just following the opening form tag element.
443 * @param string $content Content to display. Default empty.
444 * @param array $args Array of login form arguments.
446 $login_form_top = apply_filters( 'login_form_top', '', $args );
449 * Filter content to display in the middle of the login form.
451 * The filter evaluates just following the location where the 'login-password'
452 * field is displayed.
456 * @param string $content Content to display. Default empty.
457 * @param array $args Array of login form arguments.
459 $login_form_middle = apply_filters( 'login_form_middle', '', $args );
462 * Filter content to display at the bottom of the login form.
464 * The filter evaluates just preceding the closing form tag element.
468 * @param string $content Content to display. Default empty.
469 * @param array $args Array of login form arguments.
471 $login_form_bottom = apply_filters( 'login_form_bottom', '', $args );
474 <form name="' . $args['form_id'] . '" id="' . $args['form_id'] . '" action="' . esc_url( site_url( 'wp-login.php', 'login_post' ) ) . '" method="post">
475 ' . $login_form_top . '
476 <p class="login-username">
477 <label for="' . esc_attr( $args['id_username'] ) . '">' . esc_html( $args['label_username'] ) . '</label>
478 <input type="text" name="log" id="' . esc_attr( $args['id_username'] ) . '" class="input" value="' . esc_attr( $args['value_username'] ) . '" size="20" />
480 <p class="login-password">
481 <label for="' . esc_attr( $args['id_password'] ) . '">' . esc_html( $args['label_password'] ) . '</label>
482 <input type="password" name="pwd" id="' . esc_attr( $args['id_password'] ) . '" class="input" value="" size="20" />
484 ' . $login_form_middle . '
485 ' . ( $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>' : '' ) . '
486 <p class="login-submit">
487 <input type="submit" name="wp-submit" id="' . esc_attr( $args['id_submit'] ) . '" class="button-primary" value="' . esc_attr( $args['label_log_in'] ) . '" />
488 <input type="hidden" name="redirect_to" value="' . esc_url( $args['redirect'] ) . '" />
490 ' . $login_form_bottom . '
500 * Returns the URL that allows the user to retrieve the lost password
504 * @param string $redirect Path to redirect to on login.
505 * @return string Lost password URL.
507 function wp_lostpassword_url( $redirect = '' ) {
508 $args = array( 'action' => 'lostpassword' );
509 if ( !empty($redirect) ) {
510 $args['redirect_to'] = $redirect;
513 $lostpassword_url = add_query_arg( $args, network_site_url('wp-login.php', 'login') );
516 * Filter the Lost Password URL.
520 * @param string $lostpassword_url The lost password page URL.
521 * @param string $redirect The path to redirect to on login.
523 return apply_filters( 'lostpassword_url', $lostpassword_url, $redirect );
527 * Display the Registration or Admin link.
529 * Display a link which allows the user to navigate to the registration page if
530 * not logged in and registration is enabled or to the dashboard if logged in.
534 * @param string $before Text to output before the link. Default `<li>`.
535 * @param string $after Text to output after the link. Default `</li>`.
536 * @param bool $echo Default to echo and not return the link.
537 * @return string|void String when retrieving.
539 function wp_register( $before = '<li>', $after = '</li>', $echo = true ) {
540 if ( ! is_user_logged_in() ) {
541 if ( get_option('users_can_register') )
542 $link = $before . '<a href="' . esc_url( wp_registration_url() ) . '">' . __('Register') . '</a>' . $after;
545 } elseif ( current_user_can( 'read' ) ) {
546 $link = $before . '<a href="' . admin_url() . '">' . __('Site Admin') . '</a>' . $after;
552 * Filter the HTML link to the Registration or Admin page.
554 * Users are sent to the admin page if logged-in, or the registration page
555 * if enabled and logged-out.
559 * @param string $link The HTML code for the link to the Registration or Admin page.
561 $link = apply_filters( 'register', $link );
571 * Theme container function for the 'wp_meta' action.
573 * The 'wp_meta' action can have several purposes, depending on how you use it,
574 * but one purpose might have been to allow for theme switching.
578 * @link https://core.trac.wordpress.org/ticket/1458 Explanation of 'wp_meta' action.
582 * Fires before displaying echoed content in the sidebar.
586 do_action( 'wp_meta' );
590 * Display information about the blog.
592 * @see get_bloginfo() For possible values for the parameter.
595 * @param string $show What to display.
597 function bloginfo( $show='' ) {
598 echo get_bloginfo( $show, 'display' );
602 * Retrieve information about the blog.
604 * Some show parameter values are deprecated and will be removed in future
605 * versions. These options will trigger the {@see _deprecated_argument()}
606 * function. The deprecated blog info options are listed in the function
609 * The possible values for the 'show' parameter are listed below.
611 * 1. url - Blog URI to homepage.
612 * 2. wpurl - Blog URI path to WordPress.
613 * 3. description - Secondary title
615 * The feed URL options can be retrieved from 'rdf_url' (RSS 0.91),
616 * 'rss_url' (RSS 1.0), 'rss2_url' (RSS 2.0), or 'atom_url' (Atom feed). The
617 * comment feeds can be retrieved from the 'comments_atom_url' (Atom comment
618 * feed) or 'comments_rss2_url' (RSS 2.0 comment feed).
622 * @global string $wp_version
624 * @param string $show Blog info to retrieve.
625 * @param string $filter How to filter what is retrieved.
626 * @return string Mostly string values, might be empty.
628 function get_bloginfo( $show = '', $filter = 'raw' ) {
630 case 'home' : // DEPRECATED
631 case 'siteurl' : // DEPRECATED
632 _deprecated_argument( __FUNCTION__, '2.2', sprintf(
633 /* translators: 1: 'siteurl'/'home' argument, 2: bloginfo() function name, 3: 'url' argument */
634 __( 'The %1$s option is deprecated for the family of %2$s functions. Use the %3$s option instead.' ),
635 '<code>' . $show . '</code>',
636 '<code>bloginfo()</code>',
640 $output = home_url();
643 $output = site_url();
646 $output = get_option('blogdescription');
649 $output = get_feed_link('rdf');
652 $output = get_feed_link('rss');
655 $output = get_feed_link('rss2');
658 $output = get_feed_link('atom');
660 case 'comments_atom_url':
661 $output = get_feed_link('comments_atom');
663 case 'comments_rss2_url':
664 $output = get_feed_link('comments_rss2');
667 $output = site_url( 'xmlrpc.php' );
669 case 'stylesheet_url':
670 $output = get_stylesheet_uri();
672 case 'stylesheet_directory':
673 $output = get_stylesheet_directory_uri();
675 case 'template_directory':
677 $output = get_template_directory_uri();
680 $output = get_option('admin_email');
683 $output = get_option('blog_charset');
684 if ('' == $output) $output = 'UTF-8';
687 $output = get_option('html_type');
691 $output = $wp_version;
694 $output = get_locale();
695 $output = str_replace('_', '-', $output);
697 case 'text_direction':
698 _deprecated_argument( __FUNCTION__, '2.2', sprintf(
699 /* translators: 1: 'text_direction' argument, 2: bloginfo() function name, 3: is_rtl() function name */
700 __( 'The %1$s option is deprecated for the family of %2$s functions. Use the %3$s function instead.' ),
701 '<code>' . $show . '</code>',
702 '<code>bloginfo()</code>',
703 '<code>is_rtl()</code>'
705 if ( function_exists( 'is_rtl' ) ) {
706 $output = is_rtl() ? 'rtl' : 'ltr';
713 $output = get_option('blogname');
718 if (strpos($show, 'url') === false &&
719 strpos($show, 'directory') === false &&
720 strpos($show, 'home') === false)
723 if ( 'display' == $filter ) {
726 * Filter the URL returned by get_bloginfo().
730 * @param mixed $output The URL returned by bloginfo().
731 * @param mixed $show Type of information requested.
733 $output = apply_filters( 'bloginfo_url', $output, $show );
736 * Filter the site information returned by get_bloginfo().
740 * @param mixed $output The requested non-URL site information.
741 * @param mixed $show Type of information requested.
743 $output = apply_filters( 'bloginfo', $output, $show );
751 * Returns the Site Icon URL.
755 * @param int $size Optional. Size of the site icon. Default 512 (pixels).
756 * @param string $url Optional. Fallback url if no site icon is found. Default empty.
757 * @param int $blog_id Optional. ID of the blog to get the site icon for. Default current blog.
758 * @return string Site Icon URL.
760 function get_site_icon_url( $size = 512, $url = '', $blog_id = 0 ) {
761 if ( is_multisite() && (int) $blog_id !== get_current_blog_id() ) {
762 switch_to_blog( $blog_id );
765 $site_icon_id = get_option( 'site_icon' );
767 if ( $site_icon_id ) {
768 if ( $size >= 512 ) {
771 $size_data = array( $size, $size );
773 $url = wp_get_attachment_image_url( $site_icon_id, $size_data );
776 if ( is_multisite() && ms_is_switched() ) {
777 restore_current_blog();
781 * Filter the site icon URL.
785 * @param string $url Site icon URL.
786 * @param int $size Size of the site icon.
787 * @param int $blog_id ID of the blog to get the site icon for.
789 return apply_filters( 'get_site_icon_url', $url, $size, $blog_id );
793 * Displays the Site Icon URL.
797 * @param int $size Optional. Size of the site icon. Default 512 (pixels).
798 * @param string $url Optional. Fallback url if no site icon is found. Default empty.
799 * @param int $blog_id Optional. ID of the blog to get the site icon for. Default current blog.
801 function site_icon_url( $size = 512, $url = '', $blog_id = 0 ) {
802 echo esc_url( get_site_icon_url( $size, $url, $blog_id ) );
806 * Whether the site has a Site Icon.
810 * @param int $blog_id Optional. ID of the blog in question. Default current blog.
811 * @return bool Whether the site has a site icon or not.
813 function has_site_icon( $blog_id = 0 ) {
814 return (bool) get_site_icon_url( 512, '', $blog_id );
818 * Returns document title for the current page.
822 * @global int $page Page number of a single post.
823 * @global int $paged Page number of a list of posts.
825 * @return string Tag with the document title.
827 function wp_get_document_title() {
830 * Filter the document title before it is generated.
832 * Passing a non-empty value will short-circuit wp_get_document_title(),
833 * returning that value instead.
837 * @param string $title The document title. Default empty string.
839 $title = apply_filters( 'pre_get_document_title', '' );
840 if ( ! empty( $title ) ) {
844 global $page, $paged;
850 // If it's a 404 page, use a "Page not found" title.
852 $title['title'] = __( 'Page not found' );
854 // If it's a search, use a dynamic search results title.
855 } elseif ( is_search() ) {
856 /* translators: %s: search phrase */
857 $title['title'] = sprintf( __( 'Search Results for “%s”' ), get_search_query() );
859 // If on the front page, use the site title.
860 } elseif ( is_front_page() ) {
861 $title['title'] = get_bloginfo( 'name', 'display' );
863 // If on a post type archive, use the post type archive title.
864 } elseif ( is_post_type_archive() ) {
865 $title['title'] = post_type_archive_title( '', false );
867 // If on a taxonomy archive, use the term title.
868 } elseif ( is_tax() ) {
869 $title['title'] = single_term_title( '', false );
872 * If we're on the blog page that is not the homepage or
873 * a single post of any post type, use the post title.
875 } elseif ( is_home() || is_singular() ) {
876 $title['title'] = single_post_title( '', false );
878 // If on a category or tag archive, use the term title.
879 } elseif ( is_category() || is_tag() ) {
880 $title['title'] = single_term_title( '', false );
882 // If on an author archive, use the author's display name.
883 } elseif ( is_author() && $author = get_queried_object() ) {
884 $title['title'] = $author->display_name;
886 // If it's a date archive, use the date as the title.
887 } elseif ( is_year() ) {
888 $title['title'] = get_the_date( _x( 'Y', 'yearly archives date format' ) );
890 } elseif ( is_month() ) {
891 $title['title'] = get_the_date( _x( 'F Y', 'monthly archives date format' ) );
893 } elseif ( is_day() ) {
894 $title['title'] = get_the_date();
897 // Add a page number if necessary.
898 if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
899 $title['page'] = sprintf( __( 'Page %s' ), max( $paged, $page ) );
902 // Append the description or site title to give context.
903 if ( is_front_page() ) {
904 $title['tagline'] = get_bloginfo( 'description', 'display' );
906 $title['site'] = get_bloginfo( 'name', 'display' );
910 * Filter the separator for the document title.
914 * @param string $sep Document title separator. Default '-'.
916 $sep = apply_filters( 'document_title_separator', '-' );
919 * Filter the parts of the document title.
923 * @param array $title {
924 * The document title parts.
926 * @type string $title Title of the viewed page.
927 * @type string $page Optional. Page number if paginated.
928 * @type string $tagline Optional. Site description when on home page.
929 * @type string $site Optional. Site title when not on home page.
932 $title = apply_filters( 'document_title_parts', $title );
934 $title = implode( " $sep ", array_filter( $title ) );
935 $title = wptexturize( $title );
936 $title = convert_chars( $title );
937 $title = esc_html( $title );
938 $title = capital_P_dangit( $title );
944 * Displays title tag with content.
948 * @since 4.4.0 Improved title output replaced `wp_title()`.
951 function _wp_render_title_tag() {
952 if ( ! current_theme_supports( 'title-tag' ) ) {
956 echo '<title>' . wp_get_document_title() . '</title>' . "\n";
960 * Display or retrieve page title for all areas of blog.
962 * By default, the page title will display the separator before the page title,
963 * so that the blog title will be before the page title. This is not good for
964 * title display, since the blog title shows up on most tabs and not what is
965 * important, which is the page that the user is looking at.
967 * There are also SEO benefits to having the blog title after or to the 'right'
968 * or the page title. However, it is mostly common sense to have the blog title
969 * to the right with most browsers supporting tabs. You can achieve this by
970 * using the seplocation parameter and setting the value to 'right'. This change
971 * was introduced around 2.5.0, in case backwards compatibility of themes is
976 * @global WP_Locale $wp_locale
978 * @param string $sep Optional, default is '»'. How to separate the various items
979 * within the page title.
980 * @param bool $display Optional, default is true. Whether to display or retrieve title.
981 * @param string $seplocation Optional. Direction to display title, 'right'.
982 * @return string|null String on retrieve, null when displaying.
984 function wp_title( $sep = '»', $display = true, $seplocation = '' ) {
987 $m = get_query_var( 'm' );
988 $year = get_query_var( 'year' );
989 $monthnum = get_query_var( 'monthnum' );
990 $day = get_query_var( 'day' );
991 $search = get_query_var( 's' );
994 $t_sep = '%WP_TITILE_SEP%'; // Temporary separator, for accurate flipping, if necessary
996 // If there is a post
997 if ( is_single() || ( is_home() && ! is_front_page() ) || ( is_page() && ! is_front_page() ) ) {
998 $title = single_post_title( '', false );
1001 // If there's a post type archive
1002 if ( is_post_type_archive() ) {
1003 $post_type = get_query_var( 'post_type' );
1004 if ( is_array( $post_type ) ) {
1005 $post_type = reset( $post_type );
1007 $post_type_object = get_post_type_object( $post_type );
1008 if ( ! $post_type_object->has_archive ) {
1009 $title = post_type_archive_title( '', false );
1013 // If there's a category or tag
1014 if ( is_category() || is_tag() ) {
1015 $title = single_term_title( '', false );
1018 // If there's a taxonomy
1020 $term = get_queried_object();
1022 $tax = get_taxonomy( $term->taxonomy );
1023 $title = single_term_title( $tax->labels->name . $t_sep, false );
1027 // If there's an author
1028 if ( is_author() && ! is_post_type_archive() ) {
1029 $author = get_queried_object();
1031 $title = $author->display_name;
1035 // Post type archives with has_archive should override terms.
1036 if ( is_post_type_archive() && $post_type_object->has_archive ) {
1037 $title = post_type_archive_title( '', false );
1040 // If there's a month
1041 if ( is_archive() && ! empty( $m ) ) {
1042 $my_year = substr( $m, 0, 4 );
1043 $my_month = $wp_locale->get_month( substr( $m, 4, 2 ) );
1044 $my_day = intval( substr( $m, 6, 2 ) );
1045 $title = $my_year . ( $my_month ? $t_sep . $my_month : '' ) . ( $my_day ? $t_sep . $my_day : '' );
1048 // If there's a year
1049 if ( is_archive() && ! empty( $year ) ) {
1051 if ( ! empty( $monthnum ) ) {
1052 $title .= $t_sep . $wp_locale->get_month( $monthnum );
1054 if ( ! empty( $day ) ) {
1055 $title .= $t_sep . zeroise( $day, 2 );
1060 if ( is_search() ) {
1061 /* translators: 1: separator, 2: search phrase */
1062 $title = sprintf( __( 'Search Results %1$s %2$s' ), $t_sep, strip_tags( $search ) );
1065 // If it's a 404 page
1067 $title = __( 'Page not found' );
1071 if ( ! empty( $title ) ) {
1076 * Filter the parts of the page title.
1080 * @param array $title_array Parts of the page title.
1082 $title_array = apply_filters( 'wp_title_parts', explode( $t_sep, $title ) );
1084 // Determines position of the separator and direction of the breadcrumb
1085 if ( 'right' == $seplocation ) { // sep on right, so reverse the order
1086 $title_array = array_reverse( $title_array );
1087 $title = implode( " $sep ", $title_array ) . $prefix;
1089 $title = $prefix . implode( " $sep ", $title_array );
1093 * Filter the text of the page title.
1097 * @param string $title Page title.
1098 * @param string $sep Title separator.
1099 * @param string $seplocation Location of the separator (left or right).
1101 $title = apply_filters( 'wp_title', $title, $sep, $seplocation );
1112 * Display or retrieve page title for post.
1114 * This is optimized for single.php template file for displaying the post title.
1116 * It does not support placing the separator after the title, but by leaving the
1117 * prefix parameter empty, you can set the title separator manually. The prefix
1118 * does not automatically place a space between the prefix, so if there should
1119 * be a space, the parameter value will need to have it at the end.
1123 * @param string $prefix Optional. What to display before the title.
1124 * @param bool $display Optional, default is true. Whether to display or retrieve title.
1125 * @return string|void Title when retrieving.
1127 function single_post_title( $prefix = '', $display = true ) {
1128 $_post = get_queried_object();
1130 if ( !isset($_post->post_title) )
1134 * Filter the page title for a single post.
1138 * @param string $_post_title The single post page title.
1139 * @param object $_post The current queried object as returned by get_queried_object().
1141 $title = apply_filters( 'single_post_title', $_post->post_title, $_post );
1143 echo $prefix . $title;
1145 return $prefix . $title;
1149 * Display or retrieve title for a post type archive.
1151 * This is optimized for archive.php and archive-{$post_type}.php template files
1152 * for displaying the title of the post type.
1156 * @param string $prefix Optional. What to display before the title.
1157 * @param bool $display Optional, default is true. Whether to display or retrieve title.
1158 * @return string|void Title when retrieving, null when displaying or failure.
1160 function post_type_archive_title( $prefix = '', $display = true ) {
1161 if ( ! is_post_type_archive() )
1164 $post_type = get_query_var( 'post_type' );
1165 if ( is_array( $post_type ) )
1166 $post_type = reset( $post_type );
1168 $post_type_obj = get_post_type_object( $post_type );
1171 * Filter the post type archive title.
1175 * @param string $post_type_name Post type 'name' label.
1176 * @param string $post_type Post type.
1178 $title = apply_filters( 'post_type_archive_title', $post_type_obj->labels->name, $post_type );
1181 echo $prefix . $title;
1183 return $prefix . $title;
1187 * Display or retrieve page title for category archive.
1189 * Useful for category template files for displaying the category page title.
1190 * The prefix does not automatically place a space between the prefix, so if
1191 * there should be a space, the parameter value will need to have it at the end.
1195 * @param string $prefix Optional. What to display before the title.
1196 * @param bool $display Optional, default is true. Whether to display or retrieve title.
1197 * @return string|void Title when retrieving.
1199 function single_cat_title( $prefix = '', $display = true ) {
1200 return single_term_title( $prefix, $display );
1204 * Display or retrieve page title for tag post archive.
1206 * Useful for tag template files for displaying the tag page title. The prefix
1207 * does not automatically place a space between the prefix, so if there should
1208 * be a space, the parameter value will need to have it at the end.
1212 * @param string $prefix Optional. What to display before the title.
1213 * @param bool $display Optional, default is true. Whether to display or retrieve title.
1214 * @return string|void Title when retrieving.
1216 function single_tag_title( $prefix = '', $display = true ) {
1217 return single_term_title( $prefix, $display );
1221 * Display or retrieve page title for taxonomy term archive.
1223 * Useful for taxonomy term template files for displaying the taxonomy term page title.
1224 * The prefix does not automatically place a space between the prefix, so if there should
1225 * be a space, the parameter value will need to have it at the end.
1229 * @param string $prefix Optional. What to display before the title.
1230 * @param bool $display Optional, default is true. Whether to display or retrieve title.
1231 * @return string|void Title when retrieving.
1233 function single_term_title( $prefix = '', $display = true ) {
1234 $term = get_queried_object();
1239 if ( is_category() ) {
1241 * Filter the category archive page title.
1245 * @param string $term_name Category name for archive being displayed.
1247 $term_name = apply_filters( 'single_cat_title', $term->name );
1248 } elseif ( is_tag() ) {
1250 * Filter the tag archive page title.
1254 * @param string $term_name Tag name for archive being displayed.
1256 $term_name = apply_filters( 'single_tag_title', $term->name );
1257 } elseif ( is_tax() ) {
1259 * Filter the custom taxonomy archive page title.
1263 * @param string $term_name Term name for archive being displayed.
1265 $term_name = apply_filters( 'single_term_title', $term->name );
1270 if ( empty( $term_name ) )
1274 echo $prefix . $term_name;
1276 return $prefix . $term_name;
1280 * Display or retrieve page title for post archive based on date.
1282 * Useful for when the template only needs to display the month and year,
1283 * if either are available. The prefix does not automatically place a space
1284 * between the prefix, so if there should be a space, the parameter value
1285 * will need to have it at the end.
1289 * @global WP_Locale $wp_locale
1291 * @param string $prefix Optional. What to display before the title.
1292 * @param bool $display Optional, default is true. Whether to display or retrieve title.
1293 * @return string|void Title when retrieving.
1295 function single_month_title($prefix = '', $display = true ) {
1298 $m = get_query_var('m');
1299 $year = get_query_var('year');
1300 $monthnum = get_query_var('monthnum');
1302 if ( !empty($monthnum) && !empty($year) ) {
1304 $my_month = $wp_locale->get_month($monthnum);
1305 } elseif ( !empty($m) ) {
1306 $my_year = substr($m, 0, 4);
1307 $my_month = $wp_locale->get_month(substr($m, 4, 2));
1310 if ( empty($my_month) )
1313 $result = $prefix . $my_month . $prefix . $my_year;
1321 * Display the archive title based on the queried object.
1325 * @see get_the_archive_title()
1327 * @param string $before Optional. Content to prepend to the title. Default empty.
1328 * @param string $after Optional. Content to append to the title. Default empty.
1330 function the_archive_title( $before = '', $after = '' ) {
1331 $title = get_the_archive_title();
1333 if ( ! empty( $title ) ) {
1334 echo $before . $title . $after;
1339 * Retrieve the archive title based on the queried object.
1343 * @return string Archive title.
1345 function get_the_archive_title() {
1346 if ( is_category() ) {
1347 $title = sprintf( __( 'Category: %s' ), single_cat_title( '', false ) );
1348 } elseif ( is_tag() ) {
1349 $title = sprintf( __( 'Tag: %s' ), single_tag_title( '', false ) );
1350 } elseif ( is_author() ) {
1351 $title = sprintf( __( 'Author: %s' ), '<span class="vcard">' . get_the_author() . '</span>' );
1352 } elseif ( is_year() ) {
1353 $title = sprintf( __( 'Year: %s' ), get_the_date( _x( 'Y', 'yearly archives date format' ) ) );
1354 } elseif ( is_month() ) {
1355 $title = sprintf( __( 'Month: %s' ), get_the_date( _x( 'F Y', 'monthly archives date format' ) ) );
1356 } elseif ( is_day() ) {
1357 $title = sprintf( __( 'Day: %s' ), get_the_date( _x( 'F j, Y', 'daily archives date format' ) ) );
1358 } elseif ( is_tax( 'post_format' ) ) {
1359 if ( is_tax( 'post_format', 'post-format-aside' ) ) {
1360 $title = _x( 'Asides', 'post format archive title' );
1361 } elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) {
1362 $title = _x( 'Galleries', 'post format archive title' );
1363 } elseif ( is_tax( 'post_format', 'post-format-image' ) ) {
1364 $title = _x( 'Images', 'post format archive title' );
1365 } elseif ( is_tax( 'post_format', 'post-format-video' ) ) {
1366 $title = _x( 'Videos', 'post format archive title' );
1367 } elseif ( is_tax( 'post_format', 'post-format-quote' ) ) {
1368 $title = _x( 'Quotes', 'post format archive title' );
1369 } elseif ( is_tax( 'post_format', 'post-format-link' ) ) {
1370 $title = _x( 'Links', 'post format archive title' );
1371 } elseif ( is_tax( 'post_format', 'post-format-status' ) ) {
1372 $title = _x( 'Statuses', 'post format archive title' );
1373 } elseif ( is_tax( 'post_format', 'post-format-audio' ) ) {
1374 $title = _x( 'Audio', 'post format archive title' );
1375 } elseif ( is_tax( 'post_format', 'post-format-chat' ) ) {
1376 $title = _x( 'Chats', 'post format archive title' );
1378 } elseif ( is_post_type_archive() ) {
1379 $title = sprintf( __( 'Archives: %s' ), post_type_archive_title( '', false ) );
1380 } elseif ( is_tax() ) {
1381 $tax = get_taxonomy( get_queried_object()->taxonomy );
1382 /* translators: 1: Taxonomy singular name, 2: Current taxonomy term */
1383 $title = sprintf( __( '%1$s: %2$s' ), $tax->labels->singular_name, single_term_title( '', false ) );
1385 $title = __( 'Archives' );
1389 * Filter the archive title.
1393 * @param string $title Archive title to be displayed.
1395 return apply_filters( 'get_the_archive_title', $title );
1399 * Display category, tag, or term description.
1403 * @see get_the_archive_description()
1405 * @param string $before Optional. Content to prepend to the description. Default empty.
1406 * @param string $after Optional. Content to append to the description. Default empty.
1408 function the_archive_description( $before = '', $after = '' ) {
1409 $description = get_the_archive_description();
1410 if ( $description ) {
1411 echo $before . $description . $after;
1416 * Retrieve category, tag, or term description.
1420 * @return string Archive description.
1422 function get_the_archive_description() {
1424 * Filter the archive description.
1428 * @see term_description()
1430 * @param string $description Archive description to be displayed.
1432 return apply_filters( 'get_the_archive_description', term_description() );
1436 * Retrieve archive link content based on predefined or custom code.
1438 * The format can be one of four styles. The 'link' for head element, 'option'
1439 * for use in the select element, 'html' for use in list (either ol or ul HTML
1440 * elements). Custom content is also supported using the before and after
1443 * The 'link' format uses the `<link>` HTML element with the **archives**
1444 * relationship. The before and after parameters are not used. The text
1445 * parameter is used to describe the link.
1447 * The 'option' format uses the option HTML element for use in select element.
1448 * The value is the url parameter and the before and after parameters are used
1449 * between the text description.
1451 * The 'html' format, which is the default, uses the li HTML element for use in
1452 * the list HTML elements. The before parameter is before the link and the after
1453 * parameter is after the closing link.
1455 * The custom format uses the before parameter before the link ('a' HTML
1456 * element) and the after parameter after the closing link tag. If the above
1457 * three values for the format are not used, then custom format is assumed.
1461 * @todo Properly document optional arguments as such
1463 * @param string $url URL to archive.
1464 * @param string $text Archive text description.
1465 * @param string $format Optional, default is 'html'. Can be 'link', 'option', 'html', or custom.
1466 * @param string $before Optional.
1467 * @param string $after Optional.
1468 * @return string HTML link content for archive.
1470 function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') {
1471 $text = wptexturize($text);
1472 $url = esc_url($url);
1474 if ('link' == $format)
1475 $link_html = "\t<link rel='archives' title='" . esc_attr( $text ) . "' href='$url' />\n";
1476 elseif ('option' == $format)
1477 $link_html = "\t<option value='$url'>$before $text $after</option>\n";
1478 elseif ('html' == $format)
1479 $link_html = "\t<li>$before<a href='$url'>$text</a>$after</li>\n";
1481 $link_html = "\t$before<a href='$url'>$text</a>$after\n";
1484 * Filter the archive link content.
1488 * @param string $link_html The archive HTML link content.
1490 return apply_filters( 'get_archives_link', $link_html );
1494 * Display archive links based on type and format.
1497 * @since 4.4.0 $post_type arg was added.
1499 * @see get_archives_link()
1501 * @global wpdb $wpdb
1502 * @global WP_Locale $wp_locale
1504 * @param string|array $args {
1505 * Default archive links arguments. Optional.
1507 * @type string $type Type of archive to retrieve. Accepts 'daily', 'weekly', 'monthly',
1508 * 'yearly', 'postbypost', or 'alpha'. Both 'postbypost' and 'alpha'
1509 * display the same archive link list as well as post titles instead
1510 * of displaying dates. The difference between the two is that 'alpha'
1511 * will order by post title and 'postbypost' will order by post date.
1512 * Default 'monthly'.
1513 * @type string|int $limit Number of links to limit the query to. Default empty (no limit).
1514 * @type string $format Format each link should take using the $before and $after args.
1515 * Accepts 'link' (`<link>` tag), 'option' (`<option>` tag), 'html'
1516 * (`<li>` tag), or a custom format, which generates a link anchor
1517 * with $before preceding and $after succeeding. Default 'html'.
1518 * @type string $before Markup to prepend to the beginning of each link. Default empty.
1519 * @type string $after Markup to append to the end of each link. Default empty.
1520 * @type bool $show_post_count Whether to display the post count alongside the link. Default false.
1521 * @type bool|int $echo Whether to echo or return the links list. Default 1|true to echo.
1522 * @type string $order Whether to use ascending or descending order. Accepts 'ASC', or 'DESC'.
1524 * @type string $post_type Post type. Default 'post'.
1526 * @return string|void String when retrieving.
1528 function wp_get_archives( $args = '' ) {
1529 global $wpdb, $wp_locale;
1532 'type' => 'monthly', 'limit' => '',
1533 'format' => 'html', 'before' => '',
1534 'after' => '', 'show_post_count' => false,
1535 'echo' => 1, 'order' => 'DESC',
1536 'post_type' => 'post'
1539 $r = wp_parse_args( $args, $defaults );
1541 $post_type_object = get_post_type_object( $r['post_type'] );
1542 if ( ! is_post_type_viewable( $post_type_object ) ) {
1545 $r['post_type'] = $post_type_object->name;
1547 if ( '' == $r['type'] ) {
1548 $r['type'] = 'monthly';
1551 if ( ! empty( $r['limit'] ) ) {
1552 $r['limit'] = absint( $r['limit'] );
1553 $r['limit'] = ' LIMIT ' . $r['limit'];
1556 $order = strtoupper( $r['order'] );
1557 if ( $order !== 'ASC' ) {
1561 // this is what will separate dates on weekly archive links
1562 $archive_week_separator = '–';
1564 // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride
1565 $archive_date_format_over_ride = 0;
1567 // options for daily archive (only if you over-ride the general date format)
1568 $archive_day_date_format = 'Y/m/d';
1570 // options for weekly archive (only if you over-ride the general date format)
1571 $archive_week_start_date_format = 'Y/m/d';
1572 $archive_week_end_date_format = 'Y/m/d';
1574 if ( ! $archive_date_format_over_ride ) {
1575 $archive_day_date_format = get_option( 'date_format' );
1576 $archive_week_start_date_format = get_option( 'date_format' );
1577 $archive_week_end_date_format = get_option( 'date_format' );
1580 $sql_where = $wpdb->prepare( "WHERE post_type = %s AND post_status = 'publish'", $r['post_type'] );
1583 * Filter the SQL WHERE clause for retrieving archives.
1587 * @param string $sql_where Portion of SQL query containing the WHERE clause.
1588 * @param array $r An array of default arguments.
1590 $where = apply_filters( 'getarchives_where', $sql_where, $r );
1593 * Filter the SQL JOIN clause for retrieving archives.
1597 * @param string $sql_join Portion of SQL query containing JOIN clause.
1598 * @param array $r An array of default arguments.
1600 $join = apply_filters( 'getarchives_join', '', $r );
1604 $last_changed = wp_cache_get( 'last_changed', 'posts' );
1605 if ( ! $last_changed ) {
1606 $last_changed = microtime();
1607 wp_cache_set( 'last_changed', $last_changed, 'posts' );
1610 $limit = $r['limit'];
1612 if ( 'monthly' == $r['type'] ) {
1613 $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";
1614 $key = md5( $query );
1615 $key = "wp_get_archives:$key:$last_changed";
1616 if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
1617 $results = $wpdb->get_results( $query );
1618 wp_cache_set( $key, $results, 'posts' );
1621 $after = $r['after'];
1622 foreach ( (array) $results as $result ) {
1623 $url = get_month_link( $result->year, $result->month );
1624 if ( 'post' !== $r['post_type'] ) {
1625 $url = add_query_arg( 'post_type', $r['post_type'], $url );
1627 /* translators: 1: month name, 2: 4-digit year */
1628 $text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $result->month ), $result->year );
1629 if ( $r['show_post_count'] ) {
1630 $r['after'] = ' (' . $result->posts . ')' . $after;
1632 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
1635 } elseif ( 'yearly' == $r['type'] ) {
1636 $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";
1637 $key = md5( $query );
1638 $key = "wp_get_archives:$key:$last_changed";
1639 if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
1640 $results = $wpdb->get_results( $query );
1641 wp_cache_set( $key, $results, 'posts' );
1644 $after = $r['after'];
1645 foreach ( (array) $results as $result) {
1646 $url = get_year_link( $result->year );
1647 if ( 'post' !== $r['post_type'] ) {
1648 $url = add_query_arg( 'post_type', $r['post_type'], $url );
1650 $text = sprintf( '%d', $result->year );
1651 if ( $r['show_post_count'] ) {
1652 $r['after'] = ' (' . $result->posts . ')' . $after;
1654 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
1657 } elseif ( 'daily' == $r['type'] ) {
1658 $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";
1659 $key = md5( $query );
1660 $key = "wp_get_archives:$key:$last_changed";
1661 if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
1662 $results = $wpdb->get_results( $query );
1663 wp_cache_set( $key, $results, 'posts' );
1666 $after = $r['after'];
1667 foreach ( (array) $results as $result ) {
1668 $url = get_day_link( $result->year, $result->month, $result->dayofmonth );
1669 if ( 'post' !== $r['post_type'] ) {
1670 $url = add_query_arg( 'post_type', $r['post_type'], $url );
1672 $date = sprintf( '%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth );
1673 $text = mysql2date( $archive_day_date_format, $date );
1674 if ( $r['show_post_count'] ) {
1675 $r['after'] = ' (' . $result->posts . ')' . $after;
1677 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
1680 } elseif ( 'weekly' == $r['type'] ) {
1681 $week = _wp_mysql_week( '`post_date`' );
1682 $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";
1683 $key = md5( $query );
1684 $key = "wp_get_archives:$key:$last_changed";
1685 if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
1686 $results = $wpdb->get_results( $query );
1687 wp_cache_set( $key, $results, 'posts' );
1691 $after = $r['after'];
1692 foreach ( (array) $results as $result ) {
1693 if ( $result->week != $arc_w_last ) {
1694 $arc_year = $result->yr;
1695 $arc_w_last = $result->week;
1696 $arc_week = get_weekstartend( $result->yyyymmdd, get_option( 'start_of_week' ) );
1697 $arc_week_start = date_i18n( $archive_week_start_date_format, $arc_week['start'] );
1698 $arc_week_end = date_i18n( $archive_week_end_date_format, $arc_week['end'] );
1699 $url = sprintf( '%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', home_url(), '', '?', '=', $arc_year, '&', '=', $result->week );
1700 if ( 'post' !== $r['post_type'] ) {
1701 $url = add_query_arg( 'post_type', $r['post_type'], $url );
1703 $text = $arc_week_start . $archive_week_separator . $arc_week_end;
1704 if ( $r['show_post_count'] ) {
1705 $r['after'] = ' (' . $result->posts . ')' . $after;
1707 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
1711 } elseif ( ( 'postbypost' == $r['type'] ) || ('alpha' == $r['type'] ) ) {
1712 $orderby = ( 'alpha' == $r['type'] ) ? 'post_title ASC ' : 'post_date DESC, ID DESC ';
1713 $query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit";
1714 $key = md5( $query );
1715 $key = "wp_get_archives:$key:$last_changed";
1716 if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
1717 $results = $wpdb->get_results( $query );
1718 wp_cache_set( $key, $results, 'posts' );
1721 foreach ( (array) $results as $result ) {
1722 if ( $result->post_date != '0000-00-00 00:00:00' ) {
1723 $url = get_permalink( $result );
1724 if ( $result->post_title ) {
1725 /** This filter is documented in wp-includes/post-template.php */
1726 $text = strip_tags( apply_filters( 'the_title', $result->post_title, $result->ID ) );
1728 $text = $result->ID;
1730 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
1743 * Get number of days since the start of the week.
1747 * @param int $num Number of day.
1748 * @return int Days since the start of the week.
1750 function calendar_week_mod($num) {
1752 return ($num - $base*floor($num/$base));
1756 * Display calendar with days that have posts as links.
1758 * The calendar is cached, which will be retrieved, if it exists. If there are
1759 * no posts for the month, then it will not be displayed.
1763 * @global wpdb $wpdb
1765 * @global int $monthnum
1767 * @global WP_Locale $wp_locale
1768 * @global array $posts
1770 * @param bool $initial Optional, default is true. Use initial calendar names.
1771 * @param bool $echo Optional, default is true. Set to false for return.
1772 * @return string|void String when retrieving.
1774 function get_calendar( $initial = true, $echo = true ) {
1775 global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
1777 $key = md5( $m . $monthnum . $year );
1778 $cache = wp_cache_get( 'get_calendar', 'calendar' );
1780 if ( $cache && is_array( $cache ) && isset( $cache[ $key ] ) ) {
1781 /** This filter is documented in wp-includes/general-template.php */
1782 $output = apply_filters( 'get_calendar', $cache[ $key ] );
1792 if ( ! is_array( $cache ) ) {
1796 // Quick check. If we have no posts at all, abort!
1798 $gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1");
1800 $cache[ $key ] = '';
1801 wp_cache_set( 'get_calendar', $cache, 'calendar' );
1806 if ( isset( $_GET['w'] ) ) {
1807 $w = (int) $_GET['w'];
1809 // week_begins = 0 stands for Sunday
1810 $week_begins = (int) get_option( 'start_of_week' );
1811 $ts = current_time( 'timestamp' );
1813 // Let's figure out when we are
1814 if ( ! empty( $monthnum ) && ! empty( $year ) ) {
1815 $thismonth = zeroise( intval( $monthnum ), 2 );
1816 $thisyear = (int) $year;
1817 } elseif ( ! empty( $w ) ) {
1818 // We need to get the month from MySQL
1819 $thisyear = (int) substr( $m, 0, 4 );
1820 //it seems MySQL's weeks disagree with PHP's
1821 $d = ( ( $w - 1 ) * 7 ) + 6;
1822 $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')");
1823 } elseif ( ! empty( $m ) ) {
1824 $thisyear = (int) substr( $m, 0, 4 );
1825 if ( strlen( $m ) < 6 ) {
1828 $thismonth = zeroise( (int) substr( $m, 4, 2 ), 2 );
1831 $thisyear = gmdate( 'Y', $ts );
1832 $thismonth = gmdate( 'm', $ts );
1835 $unixmonth = mktime( 0, 0 , 0, $thismonth, 1, $thisyear );
1836 $last_day = date( 't', $unixmonth );
1838 // Get the next and previous month and year with at least one post
1839 $previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
1841 WHERE post_date < '$thisyear-$thismonth-01'
1842 AND post_type = 'post' AND post_status = 'publish'
1843 ORDER BY post_date DESC
1845 $next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
1847 WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59'
1848 AND post_type = 'post' AND post_status = 'publish'
1849 ORDER BY post_date ASC
1852 /* translators: Calendar caption: 1: month name, 2: 4-digit year */
1853 $calendar_caption = _x('%1$s %2$s', 'calendar caption');
1854 $calendar_output = '<table id="wp-calendar">
1855 <caption>' . sprintf(
1857 $wp_locale->get_month( $thismonth ),
1858 date( 'Y', $unixmonth )
1865 for ( $wdcount = 0; $wdcount <= 6; $wdcount++ ) {
1866 $myweek[] = $wp_locale->get_weekday( ( $wdcount + $week_begins ) % 7 );
1869 foreach ( $myweek as $wd ) {
1870 $day_name = $initial ? $wp_locale->get_weekday_initial( $wd ) : $wp_locale->get_weekday_abbrev( $wd );
1871 $wd = esc_attr( $wd );
1872 $calendar_output .= "\n\t\t<th scope=\"col\" title=\"$wd\">$day_name</th>";
1875 $calendar_output .= '
1883 $calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a href="' . get_month_link( $previous->year, $previous->month ) . '">« ' .
1884 $wp_locale->get_month_abbrev( $wp_locale->get_month( $previous->month ) ) .
1887 $calendar_output .= "\n\t\t".'<td colspan="3" id="prev" class="pad"> </td>';
1890 $calendar_output .= "\n\t\t".'<td class="pad"> </td>';
1893 $calendar_output .= "\n\t\t".'<td colspan="3" id="next"><a href="' . get_month_link( $next->year, $next->month ) . '">' .
1894 $wp_locale->get_month_abbrev( $wp_locale->get_month( $next->month ) ) .
1895 ' »</a></td>';
1897 $calendar_output .= "\n\t\t".'<td colspan="3" id="next" class="pad"> </td>';
1900 $calendar_output .= '
1907 $daywithpost = array();
1909 // Get days with posts
1910 $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
1911 FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00'
1912 AND post_type = 'post' AND post_status = 'publish'
1913 AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N);
1914 if ( $dayswithposts ) {
1915 foreach ( (array) $dayswithposts as $daywith ) {
1916 $daywithpost[] = $daywith[0];
1920 // See how much we should pad in the beginning
1921 $pad = calendar_week_mod( date( 'w', $unixmonth ) - $week_begins );
1923 $calendar_output .= "\n\t\t".'<td colspan="'. esc_attr( $pad ) .'" class="pad"> </td>';
1927 $daysinmonth = (int) date( 't', $unixmonth );
1929 for ( $day = 1; $day <= $daysinmonth; ++$day ) {
1930 if ( isset($newrow) && $newrow ) {
1931 $calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t";
1935 if ( $day == gmdate( 'j', $ts ) &&
1936 $thismonth == gmdate( 'm', $ts ) &&
1937 $thisyear == gmdate( 'Y', $ts ) ) {
1938 $calendar_output .= '<td id="today">';
1940 $calendar_output .= '<td>';
1943 if ( in_array( $day, $daywithpost ) ) {
1945 $date_format = date( _x( 'F j, Y', 'daily archives date format' ), strtotime( "{$thisyear}-{$thismonth}-{$day}" ) );
1946 $label = sprintf( __( 'Posts published on %s' ), $date_format );
1947 $calendar_output .= sprintf(
1948 '<a href="%s" aria-label="%s">%s</a>',
1949 get_day_link( $thisyear, $thismonth, $day ),
1954 $calendar_output .= $day;
1956 $calendar_output .= '</td>';
1958 if ( 6 == calendar_week_mod( date( 'w', mktime(0, 0 , 0, $thismonth, $day, $thisyear ) ) - $week_begins ) ) {
1963 $pad = 7 - calendar_week_mod( date( 'w', mktime( 0, 0 , 0, $thismonth, $day, $thisyear ) ) - $week_begins );
1964 if ( $pad != 0 && $pad != 7 ) {
1965 $calendar_output .= "\n\t\t".'<td class="pad" colspan="'. esc_attr( $pad ) .'"> </td>';
1967 $calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>";
1969 $cache[ $key ] = $calendar_output;
1970 wp_cache_set( 'get_calendar', $cache, 'calendar' );
1974 * Filter the HTML calendar output.
1978 * @param string $calendar_output HTML output of the calendar.
1980 echo apply_filters( 'get_calendar', $calendar_output );
1983 /** This filter is documented in wp-includes/general-template.php */
1984 return apply_filters( 'get_calendar', $calendar_output );
1988 * Purge the cached results of get_calendar.
1993 function delete_get_calendar_cache() {
1994 wp_cache_delete( 'get_calendar', 'calendar' );
1998 * Display all of the allowed tags in HTML format with attributes.
2000 * This is useful for displaying in the comment area, which elements and
2001 * attributes are supported. As well as any plugins which want to display it.
2005 * @global array $allowedtags
2007 * @return string HTML allowed tags entity encoded.
2009 function allowed_tags() {
2010 global $allowedtags;
2012 foreach ( (array) $allowedtags as $tag => $attributes ) {
2013 $allowed .= '<'.$tag;
2014 if ( 0 < count($attributes) ) {
2015 foreach ( $attributes as $attribute => $limits ) {
2016 $allowed .= ' '.$attribute.'=""';
2021 return htmlentities( $allowed );
2024 /***** Date/Time tags *****/
2027 * Outputs the date in iso8601 format for xml files.
2031 function the_date_xml() {
2032 echo mysql2date( 'Y-m-d', get_post()->post_date, false );
2036 * Display or Retrieve the date the current post was written (once per date)
2038 * Will only output the date if the current post's date is different from the
2039 * previous one output.
2041 * i.e. Only one date listing will show per day worth of posts shown in the loop, even if the
2042 * function is called several times for each post.
2044 * HTML output can be filtered with 'the_date'.
2045 * Date string output can be filtered with 'get_the_date'.
2049 * @global string|int|bool $currentday
2050 * @global string|int|bool $previousday
2052 * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
2053 * @param string $before Optional. Output before the date.
2054 * @param string $after Optional. Output after the date.
2055 * @param bool $echo Optional, default is display. Whether to echo the date or return it.
2056 * @return string|void String if retrieving.
2058 function the_date( $d = '', $before = '', $after = '', $echo = true ) {
2059 global $currentday, $previousday;
2061 if ( is_new_day() ) {
2062 $the_date = $before . get_the_date( $d ) . $after;
2063 $previousday = $currentday;
2066 * Filter the date a post was published for display.
2070 * @param string $the_date The formatted date string.
2071 * @param string $d PHP date format. Defaults to 'date_format' option
2073 * @param string $before HTML output before the date.
2074 * @param string $after HTML output after the date.
2076 $the_date = apply_filters( 'the_date', $the_date, $d, $before, $after );
2086 * Retrieve the date on which the post was written.
2088 * Unlike the_date() this function will always return the date.
2089 * Modify output with 'get_the_date' filter.
2093 * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
2094 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default current post.
2095 * @return false|string Date the current post was written. False on failure.
2097 function get_the_date( $d = '', $post = null ) {
2098 $post = get_post( $post );
2105 $the_date = mysql2date( get_option( 'date_format' ), $post->post_date );
2107 $the_date = mysql2date( $d, $post->post_date );
2111 * Filter the date a post was published.
2115 * @param string $the_date The formatted date.
2116 * @param string $d PHP date format. Defaults to 'date_format' option
2118 * @param int|WP_Post $post The post object or ID.
2120 return apply_filters( 'get_the_date', $the_date, $d, $post );
2124 * Display the date on which the post was last modified.
2128 * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
2129 * @param string $before Optional. Output before the date.
2130 * @param string $after Optional. Output after the date.
2131 * @param bool $echo Optional, default is display. Whether to echo the date or return it.
2132 * @return string|void String if retrieving.
2134 function the_modified_date( $d = '', $before = '', $after = '', $echo = true ) {
2135 $the_modified_date = $before . get_the_modified_date($d) . $after;
2138 * Filter the date a post was last modified for display.
2142 * @param string $the_modified_date The last modified date.
2143 * @param string $d PHP date format. Defaults to 'date_format' option
2145 * @param string $before HTML output before the date.
2146 * @param string $after HTML output after the date.
2148 $the_modified_date = apply_filters( 'the_modified_date', $the_modified_date, $d, $before, $after );
2151 echo $the_modified_date;
2153 return $the_modified_date;
2158 * Retrieve the date on which the post was last modified.
2162 * @param string $d Optional. PHP date format. Defaults to the "date_format" option
2165 function get_the_modified_date($d = '') {
2167 $the_time = get_post_modified_time(get_option('date_format'), null, null, true);
2169 $the_time = get_post_modified_time($d, null, null, true);
2172 * Filter the date a post was last modified.
2176 * @param string $the_time The formatted date.
2177 * @param string $d PHP date format. Defaults to value specified in
2178 * 'date_format' option.
2180 return apply_filters( 'get_the_modified_date', $the_time, $d );
2184 * Display the time at which the post was written.
2188 * @param string $d Either 'G', 'U', or php date format.
2190 function the_time( $d = '' ) {
2192 * Filter the time a post was written for display.
2196 * @param string $get_the_time The formatted time.
2197 * @param string $d The time format. Accepts 'G', 'U',
2198 * or php date format.
2200 echo apply_filters( 'the_time', get_the_time( $d ), $d );
2204 * Retrieve the time at which the post was written.
2208 * @param string $d Optional. Format to use for retrieving the time the post
2209 * was written. Either 'G', 'U', or php date format defaults
2210 * to the value specified in the time_format option. Default empty.
2211 * @param int|WP_Post $post WP_Post object or ID. Default is global $post object.
2212 * @return false|string Formatted date string or Unix timestamp. False on failure.
2214 function get_the_time( $d = '', $post = null ) {
2215 $post = get_post($post);
2222 $the_time = get_post_time(get_option('time_format'), false, $post, true);
2224 $the_time = get_post_time($d, false, $post, true);
2227 * Filter the time a post was written.
2231 * @param string $the_time The formatted time.
2232 * @param string $d Format to use for retrieving the time the post was written.
2233 * Accepts 'G', 'U', or php date format value specified
2234 * in 'time_format' option. Default empty.
2235 * @param int|WP_Post $post WP_Post object or ID.
2237 return apply_filters( 'get_the_time', $the_time, $d, $post );
2241 * Retrieve the time at which the post was written.
2245 * @param string $d Optional. Format to use for retrieving the time the post
2246 * was written. Either 'G', 'U', or php date format. Default 'U'.
2247 * @param bool $gmt Optional. Whether to retrieve the GMT time. Default false.
2248 * @param int|WP_Post $post WP_Post object or ID. Default is global $post object.
2249 * @param bool $translate Whether to translate the time string. Default false.
2250 * @return false|string|int Formatted date string or Unix timestamp. False on failure.
2252 function get_post_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
2253 $post = get_post($post);
2260 $time = $post->post_date_gmt;
2262 $time = $post->post_date;
2264 $time = mysql2date($d, $time, $translate);
2267 * Filter the localized time a post was written.
2271 * @param string $time The formatted time.
2272 * @param string $d Format to use for retrieving the time the post was written.
2273 * Accepts 'G', 'U', or php date format. Default 'U'.
2274 * @param bool $gmt Whether to retrieve the GMT time. Default false.
2276 return apply_filters( 'get_post_time', $time, $d, $gmt );
2280 * Display the time at which the post was last modified.
2284 * @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
2286 function the_modified_time($d = '') {
2288 * Filter the localized time a post was last modified, for display.
2292 * @param string $get_the_modified_time The formatted time.
2293 * @param string $d The time format. Accepts 'G', 'U',
2294 * or php date format. Defaults to value
2295 * specified in 'time_format' option.
2297 echo apply_filters( 'the_modified_time', get_the_modified_time($d), $d );
2301 * Retrieve the time at which the post was last modified.
2305 * @param string $d Optional Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
2308 function get_the_modified_time($d = '') {
2310 $the_time = get_post_modified_time(get_option('time_format'), null, null, true);
2312 $the_time = get_post_modified_time($d, null, null, true);
2315 * Filter the localized time a post was last modified.
2319 * @param string $the_time The formatted time.
2320 * @param string $d Format to use for retrieving the time the post was
2321 * written. Accepts 'G', 'U', or php date format. Defaults
2322 * to value specified in 'time_format' option.
2324 return apply_filters( 'get_the_modified_time', $the_time, $d );
2328 * Retrieve the time at which the post was last modified.
2332 * @param string $d Optional. Format to use for retrieving the time the post
2333 * was modified. Either 'G', 'U', or php date format. Default 'U'.
2334 * @param bool $gmt Optional. Whether to retrieve the GMT time. Default false.
2335 * @param int|WP_Post $post WP_Post object or ID. Default is global $post object.
2336 * @param bool $translate Whether to translate the time string. Default false.
2337 * @return false|string Formatted date string or Unix timestamp. False on failure.
2339 function get_post_modified_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
2340 $post = get_post($post);
2347 $time = $post->post_modified_gmt;
2349 $time = $post->post_modified;
2350 $time = mysql2date($d, $time, $translate);
2353 * Filter the localized time a post was last modified.
2357 * @param string $time The formatted time.
2358 * @param string $d The date format. Accepts 'G', 'U', or php date format. Default 'U'.
2359 * @param bool $gmt Whether to return the GMT time. Default false.
2361 return apply_filters( 'get_post_modified_time', $time, $d, $gmt );
2365 * Display the weekday on which the post was written.
2369 * @global WP_Locale $wp_locale
2371 function the_weekday() {
2373 $the_weekday = $wp_locale->get_weekday( mysql2date( 'w', get_post()->post_date, false ) );
2376 * Filter the weekday on which the post was written, for display.
2380 * @param string $the_weekday
2382 echo apply_filters( 'the_weekday', $the_weekday );
2386 * Display the weekday on which the post was written.
2388 * Will only output the weekday if the current post's weekday is different from
2389 * the previous one output.
2393 * @global WP_Locale $wp_locale
2394 * @global string|int|bool $currentday
2395 * @global string|int|bool $previousweekday
2397 * @param string $before Optional Output before the date.
2398 * @param string $after Optional Output after the date.
2400 function the_weekday_date($before='',$after='') {
2401 global $wp_locale, $currentday, $previousweekday;
2402 $the_weekday_date = '';
2403 if ( $currentday != $previousweekday ) {
2404 $the_weekday_date .= $before;
2405 $the_weekday_date .= $wp_locale->get_weekday( mysql2date( 'w', get_post()->post_date, false ) );
2406 $the_weekday_date .= $after;
2407 $previousweekday = $currentday;
2411 * Filter the localized date on which the post was written, for display.
2415 * @param string $the_weekday_date
2416 * @param string $before The HTML to output before the date.
2417 * @param string $after The HTML to output after the date.
2419 $the_weekday_date = apply_filters( 'the_weekday_date', $the_weekday_date, $before, $after );
2420 echo $the_weekday_date;
2424 * Fire the wp_head action
2428 function wp_head() {
2430 * Print scripts or data in the head tag on the front end.
2434 do_action( 'wp_head' );
2438 * Fire the wp_footer action
2442 function wp_footer() {
2444 * Print scripts or data before the closing body tag on the front end.
2448 do_action( 'wp_footer' );
2452 * Display the links to the general feeds.
2456 * @param array $args Optional arguments.
2458 function feed_links( $args = array() ) {
2459 if ( !current_theme_supports('automatic-feed-links') )
2463 /* translators: Separator between blog name and feed type in feed links */
2464 'separator' => _x('»', 'feed link'),
2465 /* translators: 1: blog title, 2: separator (raquo) */
2466 'feedtitle' => __('%1$s %2$s Feed'),
2467 /* translators: 1: blog title, 2: separator (raquo) */
2468 'comstitle' => __('%1$s %2$s Comments Feed'),
2471 $args = wp_parse_args( $args, $defaults );
2474 * Filter whether to display the posts feed link.
2478 * @param bool $show Whether to display the posts feed link. Default true.
2480 if ( apply_filters( 'feed_links_show_posts_feed', true ) ) {
2481 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";
2485 * Filter whether to display the comments feed link.
2489 * @param bool $show Whether to display the comments feed link. Default true.
2491 if ( apply_filters( 'feed_links_show_comments_feed', true ) ) {
2492 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";
2497 * Display the links to the extra feeds such as category feeds.
2501 * @param array $args Optional arguments.
2503 function feed_links_extra( $args = array() ) {
2505 /* translators: Separator between blog name and feed type in feed links */
2506 'separator' => _x('»', 'feed link'),
2507 /* translators: 1: blog name, 2: separator(raquo), 3: post title */
2508 'singletitle' => __('%1$s %2$s %3$s Comments Feed'),
2509 /* translators: 1: blog name, 2: separator(raquo), 3: category name */
2510 'cattitle' => __('%1$s %2$s %3$s Category Feed'),
2511 /* translators: 1: blog name, 2: separator(raquo), 3: tag name */
2512 'tagtitle' => __('%1$s %2$s %3$s Tag Feed'),
2513 /* translators: 1: blog name, 2: separator(raquo), 3: author name */
2514 'authortitle' => __('%1$s %2$s Posts by %3$s Feed'),
2515 /* translators: 1: blog name, 2: separator(raquo), 3: search phrase */
2516 'searchtitle' => __('%1$s %2$s Search Results for “%3$s” Feed'),
2517 /* translators: 1: blog name, 2: separator(raquo), 3: post type name */
2518 'posttypetitle' => __('%1$s %2$s %3$s Feed'),
2521 $args = wp_parse_args( $args, $defaults );
2523 if ( is_singular() ) {
2525 $post = get_post( $id );
2527 if ( comments_open() || pings_open() || $post->comment_count > 0 ) {
2528 $title = sprintf( $args['singletitle'], get_bloginfo('name'), $args['separator'], the_title_attribute( array( 'echo' => false ) ) );
2529 $href = get_post_comments_feed_link( $post->ID );
2531 } elseif ( is_post_type_archive() ) {
2532 $post_type = get_query_var( 'post_type' );
2533 if ( is_array( $post_type ) )
2534 $post_type = reset( $post_type );
2536 $post_type_obj = get_post_type_object( $post_type );
2537 $title = sprintf( $args['posttypetitle'], get_bloginfo( 'name' ), $args['separator'], $post_type_obj->labels->name );
2538 $href = get_post_type_archive_feed_link( $post_type_obj->name );
2539 } elseif ( is_category() ) {
2540 $term = get_queried_object();
2543 $title = sprintf( $args['cattitle'], get_bloginfo('name'), $args['separator'], $term->name );
2544 $href = get_category_feed_link( $term->term_id );
2546 } elseif ( is_tag() ) {
2547 $term = get_queried_object();
2550 $title = sprintf( $args['tagtitle'], get_bloginfo('name'), $args['separator'], $term->name );
2551 $href = get_tag_feed_link( $term->term_id );
2553 } elseif ( is_author() ) {
2554 $author_id = intval( get_query_var('author') );
2556 $title = sprintf( $args['authortitle'], get_bloginfo('name'), $args['separator'], get_the_author_meta( 'display_name', $author_id ) );
2557 $href = get_author_feed_link( $author_id );
2558 } elseif ( is_search() ) {
2559 $title = sprintf( $args['searchtitle'], get_bloginfo('name'), $args['separator'], get_search_query( false ) );
2560 $href = get_search_feed_link();
2561 } elseif ( is_post_type_archive() ) {
2562 $title = sprintf( $args['posttypetitle'], get_bloginfo('name'), $args['separator'], post_type_archive_title( '', false ) );
2563 $post_type_obj = get_queried_object();
2564 if ( $post_type_obj )
2565 $href = get_post_type_archive_feed_link( $post_type_obj->name );
2568 if ( isset($title) && isset($href) )
2569 echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr( $title ) . '" href="' . esc_url( $href ) . '" />' . "\n";
2573 * Display the link to the Really Simple Discovery service endpoint.
2575 * @link http://archipelago.phrasewise.com/rsd
2578 function rsd_link() {
2579 echo '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . esc_url( site_url( 'xmlrpc.php?rsd', 'rpc' ) ) . '" />' . "\n";
2583 * Display the link to the Windows Live Writer manifest file.
2585 * @link http://msdn.microsoft.com/en-us/library/bb463265.aspx
2588 function wlwmanifest_link() {
2589 echo '<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="',
2590 includes_url( 'wlwmanifest.xml' ), '" /> ', "\n";
2594 * Display a noindex meta tag if required by the blog configuration.
2596 * If a blog is marked as not being public then the noindex meta tag will be
2597 * output to tell web robots not to index the page content. Add this to the wp_head action.
2598 * Typical usage is as a wp_head callback. add_action( 'wp_head', 'noindex' );
2604 function noindex() {
2605 // If the blog is not public, tell robots to go away.
2606 if ( '0' == get_option('blog_public') )
2611 * Display a noindex meta tag.
2613 * Outputs a noindex meta tag that tells web robots not to index the page content.
2614 * Typical usage is as a wp_head callback. add_action( 'wp_head', 'wp_no_robots' );
2618 function wp_no_robots() {
2619 echo "<meta name='robots' content='noindex,follow' />\n";
2623 * Display site icon meta tags.
2627 * @link http://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#rel-icon HTML5 specification link icon.
2629 function wp_site_icon() {
2630 if ( ! has_site_icon() && ! is_customize_preview() ) {
2635 sprintf( '<link rel="icon" href="%s" sizes="32x32" />', esc_url( get_site_icon_url( 32 ) ) ),
2636 sprintf( '<link rel="icon" href="%s" sizes="192x192" />', esc_url( get_site_icon_url( 192 ) ) ),
2637 sprintf( '<link rel="apple-touch-icon-precomposed" href="%s" />', esc_url( get_site_icon_url( 180 ) ) ),
2638 sprintf( '<meta name="msapplication-TileImage" content="%s" />', esc_url( get_site_icon_url( 270 ) ) ),
2642 * Filter the site icon meta tags, so Plugins can add their own.
2646 * @param array $meta_tags Site Icon meta elements.
2648 $meta_tags = apply_filters( 'site_icon_meta_tags', $meta_tags );
2649 $meta_tags = array_filter( $meta_tags );
2651 foreach ( $meta_tags as $meta_tag ) {
2657 * Whether the user should have a WYSIWIG editor.
2659 * Checks that the user requires a WYSIWIG editor and that the editor is
2660 * supported in the users browser.
2664 * @global bool $wp_rich_edit
2665 * @global bool $is_gecko
2666 * @global bool $is_opera
2667 * @global bool $is_safari
2668 * @global bool $is_chrome
2669 * @global bool $is_IE
2673 function user_can_richedit() {
2674 global $wp_rich_edit, $is_gecko, $is_opera, $is_safari, $is_chrome, $is_IE, $is_edge;
2676 if ( !isset($wp_rich_edit) ) {
2677 $wp_rich_edit = false;
2679 if ( get_user_option( 'rich_editing' ) == 'true' || ! is_user_logged_in() ) { // default to 'true' for logged out users
2681 $wp_rich_edit = ! wp_is_mobile() || ( preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match ) && intval( $match[1] ) >= 534 );
2682 } elseif ( $is_gecko || $is_chrome || $is_IE || $is_edge || ( $is_opera && !wp_is_mobile() ) ) {
2683 $wp_rich_edit = true;
2689 * Filter whether the user can access the rich (Visual) editor.
2693 * @param bool $wp_rich_edit Whether the user can access to the rich (Visual) editor.
2695 return apply_filters( 'user_can_richedit', $wp_rich_edit );
2699 * Find out which editor should be displayed by default.
2701 * Works out which of the two editors to display as the current editor for a
2702 * user. The 'html' setting is for the "Text" editor tab.
2706 * @return string Either 'tinymce', or 'html', or 'test'
2708 function wp_default_editor() {
2709 $r = user_can_richedit() ? 'tinymce' : 'html'; // defaults
2710 if ( wp_get_current_user() ) { // look for cookie
2711 $ed = get_user_setting('editor', 'tinymce');
2712 $r = ( in_array($ed, array('tinymce', 'html', 'test') ) ) ? $ed : $r;
2716 * Filter which editor should be displayed by default.
2720 * @param array $r An array of editors. Accepts 'tinymce', 'html', 'test'.
2722 return apply_filters( 'wp_default_editor', $r );
2726 * Renders an editor.
2728 * Using this function is the proper way to output all needed components for both TinyMCE and Quicktags.
2729 * _WP_Editors should not be used directly. See https://core.trac.wordpress.org/ticket/17144.
2731 * NOTE: Once initialized the TinyMCE editor cannot be safely moved in the DOM. For that reason
2732 * running wp_editor() inside of a metabox is not a good idea unless only Quicktags is used.
2733 * On the post edit screen several actions can be used to include additional editors
2734 * containing TinyMCE: 'edit_page_form', 'edit_form_advanced' and 'dbx_post_sidebar'.
2735 * See https://core.trac.wordpress.org/ticket/19173 for more information.
2737 * @see wp-includes/class-wp-editor.php
2740 * @param string $content Initial content for the editor.
2741 * @param string $editor_id HTML ID attribute value for the textarea and TinyMCE. Can only be /[a-z]+/.
2742 * @param array $settings See _WP_Editors::editor().
2744 function wp_editor( $content, $editor_id, $settings = array() ) {
2745 if ( ! class_exists( '_WP_Editors', false ) )
2746 require( ABSPATH . WPINC . '/class-wp-editor.php' );
2748 _WP_Editors::editor($content, $editor_id, $settings);
2752 * Retrieve the contents of the search WordPress query variable.
2754 * The search query string is passed through {@link esc_attr()}
2755 * to ensure that it is safe for placing in an html attribute.
2759 * @param bool $escaped Whether the result is escaped. Default true.
2760 * Only use when you are later escaping it. Do not use unescaped.
2763 function get_search_query( $escaped = true ) {
2765 * Filter the contents of the search query variable.
2769 * @param mixed $search Contents of the search query variable.
2771 $query = apply_filters( 'get_search_query', get_query_var( 's' ) );
2774 $query = esc_attr( $query );
2779 * Display the contents of the search query variable.
2781 * The search query string is passed through {@link esc_attr()}
2782 * to ensure that it is safe for placing in an html attribute.
2786 function the_search_query() {
2788 * Filter the contents of the search query variable for display.
2792 * @param mixed $search Contents of the search query variable.
2794 echo esc_attr( apply_filters( 'the_search_query', get_search_query( false ) ) );
2798 * Gets the language attributes for the html tag.
2800 * Builds up a set of html attributes containing the text direction and language
2801 * information for the page.
2805 * @param string $doctype Optional. The type of html document. Accepts 'xhtml' or 'html'. Default 'html'.
2807 function get_language_attributes( $doctype = 'html' ) {
2808 $attributes = array();
2810 if ( function_exists( 'is_rtl' ) && is_rtl() )
2811 $attributes[] = 'dir="rtl"';
2813 if ( $lang = get_bloginfo('language') ) {
2814 if ( get_option('html_type') == 'text/html' || $doctype == 'html' )
2815 $attributes[] = "lang=\"$lang\"";
2817 if ( get_option('html_type') != 'text/html' || $doctype == 'xhtml' )
2818 $attributes[] = "xml:lang=\"$lang\"";
2821 $output = implode(' ', $attributes);
2824 * Filter the language attributes for display in the html tag.
2827 * @since 4.3.0 Added the `$doctype` parameter.
2829 * @param string $output A space-separated list of language attributes.
2830 * @param string $doctype The type of html document (xhtml|html).
2832 return apply_filters( 'language_attributes', $output, $doctype );
2836 * Displays the language attributes for the html tag.
2838 * Builds up a set of html attributes containing the text direction and language
2839 * information for the page.
2842 * @since 4.3.0 Converted into a wrapper for get_language_attributes().
2844 * @param string $doctype Optional. The type of html document. Accepts 'xhtml' or 'html'. Default 'html'.
2846 function language_attributes( $doctype = 'html' ) {
2847 echo get_language_attributes( $doctype );
2851 * Retrieve paginated link for archive post pages.
2853 * Technically, the function can be used to create paginated link list for any
2854 * area. The 'base' argument is used to reference the url, which will be used to
2855 * create the paginated links. The 'format' argument is then used for replacing
2856 * the page number. It is however, most likely and by default, to be used on the
2857 * archive post pages.
2859 * The 'type' argument controls format of the returned value. The default is
2860 * 'plain', which is just a string with the links separated by a newline
2861 * character. The other possible values are either 'array' or 'list'. The
2862 * 'array' value will return an array of the paginated link list to offer full
2863 * control of display. The 'list' value will place all of the paginated links in
2864 * an unordered HTML list.
2866 * The 'total' argument is the total amount of pages and is an integer. The
2867 * 'current' argument is the current page number and is also an integer.
2869 * An example of the 'base' argument is "http://example.com/all_posts.php%_%"
2870 * and the '%_%' is required. The '%_%' will be replaced by the contents of in
2871 * the 'format' argument. An example for the 'format' argument is "?page=%#%"
2872 * and the '%#%' is also required. The '%#%' will be replaced with the page
2875 * You can include the previous and next links in the list by setting the
2876 * 'prev_next' argument to true, which it is by default. You can set the
2877 * previous text, by using the 'prev_text' argument. You can set the next text
2878 * by setting the 'next_text' argument.
2880 * If the 'show_all' argument is set to true, then it will show all of the pages
2881 * instead of a short list of the pages near the current page. By default, the
2882 * 'show_all' is set to false and controlled by the 'end_size' and 'mid_size'
2883 * arguments. The 'end_size' argument is how many numbers on either the start
2884 * and the end list edges, by default is 1. The 'mid_size' argument is how many
2885 * numbers to either side of current page, but not including current page.
2887 * It is possible to add query vars to the link by using the 'add_args' argument
2888 * and see {@link add_query_arg()} for more information.
2890 * The 'before_page_number' and 'after_page_number' arguments allow users to
2891 * augment the links themselves. Typically this might be to add context to the
2892 * numbered links so that screen reader users understand what the links are for.
2893 * The text strings are added before and after the page number - within the
2898 * @global WP_Query $wp_query
2899 * @global WP_Rewrite $wp_rewrite
2901 * @param string|array $args {
2902 * Optional. Array or string of arguments for generating paginated links for archives.
2904 * @type string $base Base of the paginated url. Default empty.
2905 * @type string $format Format for the pagination structure. Default empty.
2906 * @type int $total The total amount of pages. Default is the value WP_Query's
2907 * `max_num_pages` or 1.
2908 * @type int $current The current page number. Default is 'paged' query var or 1.
2909 * @type bool $show_all Whether to show all pages. Default false.
2910 * @type int $end_size How many numbers on either the start and the end list edges.
2912 * @type int $mid_size How many numbers to either side of the current pages. Default 2.
2913 * @type bool $prev_next Whether to include the previous and next links in the list. Default true.
2914 * @type bool $prev_text The previous page text. Default '« Previous'.
2915 * @type bool $next_text The next page text. Default '« Previous'.
2916 * @type string $type Controls format of the returned value. Possible values are 'plain',
2917 * 'array' and 'list'. Default is 'plain'.
2918 * @type array $add_args An array of query args to add. Default false.
2919 * @type string $add_fragment A string to append to each link. Default empty.
2920 * @type string $before_page_number A string to appear before the page number. Default empty.
2921 * @type string $after_page_number A string to append after the page number. Default empty.
2923 * @return array|string|void String of page links or array of page links.
2925 function paginate_links( $args = '' ) {
2926 global $wp_query, $wp_rewrite;
2928 // Setting up default values based on the current URL.
2929 $pagenum_link = html_entity_decode( get_pagenum_link() );
2930 $url_parts = explode( '?', $pagenum_link );
2932 // Get max pages and current page out of the current query, if available.
2933 $total = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1;
2934 $current = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
2936 // Append the format placeholder to the base URL.
2937 $pagenum_link = trailingslashit( $url_parts[0] ) . '%_%';
2939 // URL base depends on permalink settings.
2940 $format = $wp_rewrite->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
2941 $format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%';
2944 'base' => $pagenum_link, // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
2945 'format' => $format, // ?page=%#% : %#% is replaced by the page number
2947 'current' => $current,
2948 'show_all' => false,
2949 'prev_next' => true,
2950 'prev_text' => __('« Previous'),
2951 'next_text' => __('Next »'),
2955 'add_args' => array(), // array of query args to add
2956 'add_fragment' => '',
2957 'before_page_number' => '',
2958 'after_page_number' => ''
2961 $args = wp_parse_args( $args, $defaults );
2963 if ( ! is_array( $args['add_args'] ) ) {
2964 $args['add_args'] = array();
2967 // Merge additional query vars found in the original URL into 'add_args' array.
2968 if ( isset( $url_parts[1] ) ) {
2969 // Find the format argument.
2970 $format = explode( '?', str_replace( '%_%', $args['format'], $args['base'] ) );
2971 $format_query = isset( $format[1] ) ? $format[1] : '';
2972 wp_parse_str( $format_query, $format_args );
2974 // Find the query args of the requested URL.
2975 wp_parse_str( $url_parts[1], $url_query_args );
2977 // Remove the format argument from the array of query arguments, to avoid overwriting custom format.
2978 foreach ( $format_args as $format_arg => $format_arg_value ) {
2979 unset( $url_query_args[ $format_arg ] );
2982 $args['add_args'] = array_merge( $args['add_args'], urlencode_deep( $url_query_args ) );
2985 // Who knows what else people pass in $args
2986 $total = (int) $args['total'];
2990 $current = (int) $args['current'];
2991 $end_size = (int) $args['end_size']; // Out of bounds? Make it the default.
2992 if ( $end_size < 1 ) {
2995 $mid_size = (int) $args['mid_size'];
2996 if ( $mid_size < 0 ) {
2999 $add_args = $args['add_args'];
3001 $page_links = array();
3004 if ( $args['prev_next'] && $current && 1 < $current ) :
3005 $link = str_replace( '%_%', 2 == $current ? '' : $args['format'], $args['base'] );
3006 $link = str_replace( '%#%', $current - 1, $link );
3008 $link = add_query_arg( $add_args, $link );
3009 $link .= $args['add_fragment'];
3012 * Filter the paginated links for the given archive pages.
3016 * @param string $link The paginated link URL.
3018 $page_links[] = '<a class="prev page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $args['prev_text'] . '</a>';
3020 for ( $n = 1; $n <= $total; $n++ ) :
3021 if ( $n == $current ) :
3022 $page_links[] = "<span class='page-numbers current'>" . $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] . "</span>";
3025 if ( $args['show_all'] || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
3026 $link = str_replace( '%_%', 1 == $n ? '' : $args['format'], $args['base'] );
3027 $link = str_replace( '%#%', $n, $link );
3029 $link = add_query_arg( $add_args, $link );
3030 $link .= $args['add_fragment'];
3032 /** This filter is documented in wp-includes/general-template.php */
3033 $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>";
3035 elseif ( $dots && ! $args['show_all'] ) :
3036 $page_links[] = '<span class="page-numbers dots">' . __( '…' ) . '</span>';
3041 if ( $args['prev_next'] && $current && ( $current < $total || -1 == $total ) ) :
3042 $link = str_replace( '%_%', $args['format'], $args['base'] );
3043 $link = str_replace( '%#%', $current + 1, $link );
3045 $link = add_query_arg( $add_args, $link );
3046 $link .= $args['add_fragment'];
3048 /** This filter is documented in wp-includes/general-template.php */
3049 $page_links[] = '<a class="next page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $args['next_text'] . '</a>';
3051 switch ( $args['type'] ) {
3056 $r .= "<ul class='page-numbers'>\n\t<li>";
3057 $r .= join("</li>\n\t<li>", $page_links);
3058 $r .= "</li>\n</ul>\n";
3062 $r = join("\n", $page_links);
3069 * Registers an admin colour scheme css file.
3071 * Allows a plugin to register a new admin colour scheme. For example:
3073 * wp_admin_css_color( 'classic', __( 'Classic' ), admin_url( "css/colors-classic.css" ), array(
3074 * '#07273E', '#14568A', '#D54E21', '#2683AE'
3079 * @todo Properly document optional arguments as such
3081 * @global array $_wp_admin_css_colors
3083 * @param string $key The unique key for this theme.
3084 * @param string $name The name of the theme.
3085 * @param string $url The url of the css file containing the colour scheme.
3086 * @param array $colors Optional An array of CSS color definitions which are used to give the user a feel for the theme.
3087 * @param array $icons Optional An array of CSS color definitions used to color any SVG icons
3089 function wp_admin_css_color( $key, $name, $url, $colors = array(), $icons = array() ) {
3090 global $_wp_admin_css_colors;
3092 if ( !isset($_wp_admin_css_colors) )
3093 $_wp_admin_css_colors = array();
3095 $_wp_admin_css_colors[$key] = (object) array(
3098 'colors' => $colors,
3099 'icon_colors' => $icons,
3104 * Registers the default Admin color schemes
3108 * @global string $wp_version
3110 function register_admin_color_schemes() {
3111 $suffix = is_rtl() ? '-rtl' : '';
3112 $suffix .= SCRIPT_DEBUG ? '' : '.min';
3114 wp_admin_css_color( 'fresh', _x( 'Default', 'admin color scheme' ),
3116 array( '#222', '#333', '#0073aa', '#00a0d2' ),
3117 array( 'base' => '#999', 'focus' => '#00a0d2', 'current' => '#fff' )
3120 // Other color schemes are not available when running out of src
3121 if ( false !== strpos( $GLOBALS['wp_version'], '-src' ) )
3124 wp_admin_css_color( 'light', _x( 'Light', 'admin color scheme' ),
3125 admin_url( "css/colors/light/colors$suffix.css" ),
3126 array( '#e5e5e5', '#999', '#d64e07', '#04a4cc' ),
3127 array( 'base' => '#999', 'focus' => '#ccc', 'current' => '#ccc' )
3130 wp_admin_css_color( 'blue', _x( 'Blue', 'admin color scheme' ),
3131 admin_url( "css/colors/blue/colors$suffix.css" ),
3132 array( '#096484', '#4796b3', '#52accc', '#74B6CE' ),
3133 array( 'base' => '#e5f8ff', 'focus' => '#fff', 'current' => '#fff' )
3136 wp_admin_css_color( 'midnight', _x( 'Midnight', 'admin color scheme' ),
3137 admin_url( "css/colors/midnight/colors$suffix.css" ),
3138 array( '#25282b', '#363b3f', '#69a8bb', '#e14d43' ),
3139 array( 'base' => '#f1f2f3', 'focus' => '#fff', 'current' => '#fff' )
3142 wp_admin_css_color( 'sunrise', _x( 'Sunrise', 'admin color scheme' ),
3143 admin_url( "css/colors/sunrise/colors$suffix.css" ),
3144 array( '#b43c38', '#cf4944', '#dd823b', '#ccaf0b' ),
3145 array( 'base' => '#f3f1f1', 'focus' => '#fff', 'current' => '#fff' )
3148 wp_admin_css_color( 'ectoplasm', _x( 'Ectoplasm', 'admin color scheme' ),
3149 admin_url( "css/colors/ectoplasm/colors$suffix.css" ),
3150 array( '#413256', '#523f6d', '#a3b745', '#d46f15' ),
3151 array( 'base' => '#ece6f6', 'focus' => '#fff', 'current' => '#fff' )
3154 wp_admin_css_color( 'ocean', _x( 'Ocean', 'admin color scheme' ),
3155 admin_url( "css/colors/ocean/colors$suffix.css" ),
3156 array( '#627c83', '#738e96', '#9ebaa0', '#aa9d88' ),
3157 array( 'base' => '#f2fcff', 'focus' => '#fff', 'current' => '#fff' )
3160 wp_admin_css_color( 'coffee', _x( 'Coffee', 'admin color scheme' ),
3161 admin_url( "css/colors/coffee/colors$suffix.css" ),
3162 array( '#46403c', '#59524c', '#c7a589', '#9ea476' ),
3163 array( 'base' => '#f3f2f1', 'focus' => '#fff', 'current' => '#fff' )
3169 * Display the URL of a WordPress admin CSS file.
3171 * @see WP_Styles::_css_href and its style_loader_src filter.
3175 * @param string $file file relative to wp-admin/ without its ".css" extension.
3178 function wp_admin_css_uri( $file = 'wp-admin' ) {
3179 if ( defined('WP_INSTALLING') ) {
3180 $_file = "./$file.css";
3182 $_file = admin_url("$file.css");
3184 $_file = add_query_arg( 'version', get_bloginfo( 'version' ), $_file );
3187 * Filter the URI of a WordPress admin CSS file.
3191 * @param string $_file Relative path to the file with query arguments attached.
3192 * @param string $file Relative path to the file, minus its ".css" extension.
3194 return apply_filters( 'wp_admin_css_uri', $_file, $file );
3198 * Enqueues or directly prints a stylesheet link to the specified CSS file.
3200 * "Intelligently" decides to enqueue or to print the CSS file. If the
3201 * 'wp_print_styles' action has *not* yet been called, the CSS file will be
3202 * enqueued. If the wp_print_styles action *has* been called, the CSS link will
3203 * be printed. Printing may be forced by passing true as the $force_echo
3204 * (second) parameter.
3206 * For backward compatibility with WordPress 2.3 calling method: If the $file
3207 * (first) parameter does not correspond to a registered CSS file, we assume
3208 * $file is a file relative to wp-admin/ without its ".css" extension. A
3209 * stylesheet link to that generated URL is printed.
3213 * @param string $file Optional. Style handle name or file name (without ".css" extension) relative
3214 * to wp-admin/. Defaults to 'wp-admin'.
3215 * @param bool $force_echo Optional. Force the stylesheet link to be printed rather than enqueued.
3217 function wp_admin_css( $file = 'wp-admin', $force_echo = false ) {
3218 // For backward compatibility
3219 $handle = 0 === strpos( $file, 'css/' ) ? substr( $file, 4 ) : $file;
3221 if ( wp_styles()->query( $handle ) ) {
3222 if ( $force_echo || did_action( 'wp_print_styles' ) ) // we already printed the style queue. Print this one immediately
3223 wp_print_styles( $handle );
3224 else // Add to style queue
3225 wp_enqueue_style( $handle );
3230 * Filter the stylesheet link to the specified CSS file.
3232 * If the site is set to display right-to-left, the RTL stylesheet link
3233 * will be used instead.
3237 * @param string $file Style handle name or filename (without ".css" extension)
3238 * relative to wp-admin/. Defaults to 'wp-admin'.
3240 echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( $file ) ) . "' type='text/css' />\n", $file );
3242 if ( function_exists( 'is_rtl' ) && is_rtl() ) {
3243 /** This filter is documented in wp-includes/general-template.php */
3244 echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( "$file-rtl" ) ) . "' type='text/css' />\n", "$file-rtl" );
3249 * Enqueues the default ThickBox js and css.
3251 * If any of the settings need to be changed, this can be done with another js
3252 * file similar to media-upload.js. That file should
3253 * require array('thickbox') to ensure it is loaded after.
3257 function add_thickbox() {
3258 wp_enqueue_script( 'thickbox' );
3259 wp_enqueue_style( 'thickbox' );
3261 if ( is_network_admin() )
3262 add_action( 'admin_head', '_thickbox_path_admin_subfolder' );
3266 * Display the XHTML generator that is generated on the wp_head hook.
3270 function wp_generator() {
3272 * Filter the output of the XHTML generator tag.
3276 * @param string $generator_type The XHTML generator.
3278 the_generator( apply_filters( 'wp_generator_type', 'xhtml' ) );
3282 * Display the generator XML or Comment for RSS, ATOM, etc.
3284 * Returns the correct generator type for the requested output format. Allows
3285 * for a plugin to filter generators overall the the_generator filter.
3289 * @param string $type The type of generator to output - (html|xhtml|atom|rss2|rdf|comment|export).
3291 function the_generator( $type ) {
3293 * Filter the output of the XHTML generator tag for display.
3297 * @param string $generator_type The generator output.
3298 * @param string $type The type of generator to output. Accepts 'html',
3299 * 'xhtml', 'atom', 'rss2', 'rdf', 'comment', 'export'.
3301 echo apply_filters( 'the_generator', get_the_generator($type), $type ) . "\n";
3305 * Creates the generator XML or Comment for RSS, ATOM, etc.
3307 * Returns the correct generator type for the requested output format. Allows
3308 * for a plugin to filter generators on an individual basis using the
3309 * 'get_the_generator_{$type}' filter.
3313 * @param string $type The type of generator to return - (html|xhtml|atom|rss2|rdf|comment|export).
3314 * @return string|void The HTML content for the generator.
3316 function get_the_generator( $type = '' ) {
3317 if ( empty( $type ) ) {
3319 $current_filter = current_filter();
3320 if ( empty( $current_filter ) )
3323 switch ( $current_filter ) {
3325 case 'commentsrss2_head' :
3336 case 'comments_atom_head' :
3345 $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '">';
3348 $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '" />';
3351 $gen = '<generator uri="https://wordpress.org/" version="' . get_bloginfo_rss( 'version' ) . '">WordPress</generator>';
3354 $gen = '<generator>https://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '</generator>';
3357 $gen = '<admin:generatorAgent rdf:resource="https://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '" />';
3360 $gen = '<!-- generator="WordPress/' . get_bloginfo( 'version' ) . '" -->';
3363 $gen = '<!-- generator="WordPress/' . get_bloginfo_rss('version') . '" created="'. date('Y-m-d H:i') . '" -->';
3368 * Filter the HTML for the retrieved generator type.
3370 * The dynamic portion of the hook name, `$type`, refers to the generator type.
3374 * @param string $gen The HTML markup output to {@see wp_head()}.
3375 * @param string $type The type of generator. Accepts 'html', 'xhtml', 'atom',
3376 * 'rss2', 'rdf', 'comment', 'export'.
3378 return apply_filters( "get_the_generator_{$type}", $gen, $type );
3382 * Outputs the html checked attribute.
3384 * Compares the first two arguments and if identical marks as checked
3388 * @param mixed $checked One of the values to compare
3389 * @param mixed $current (true) The other value to compare if not just true
3390 * @param bool $echo Whether to echo or just return the string
3391 * @return string html attribute or empty string
3393 function checked( $checked, $current = true, $echo = true ) {
3394 return __checked_selected_helper( $checked, $current, $echo, 'checked' );
3398 * Outputs the html selected attribute.
3400 * Compares the first two arguments and if identical marks as selected
3404 * @param mixed $selected One of the values to compare
3405 * @param mixed $current (true) The other value to compare if not just true
3406 * @param bool $echo Whether to echo or just return the string
3407 * @return string html attribute or empty string
3409 function selected( $selected, $current = true, $echo = true ) {
3410 return __checked_selected_helper( $selected, $current, $echo, 'selected' );
3414 * Outputs the html disabled attribute.
3416 * Compares the first two arguments and if identical marks as disabled
3420 * @param mixed $disabled One of the values to compare
3421 * @param mixed $current (true) The other value to compare if not just true
3422 * @param bool $echo Whether to echo or just return the string
3423 * @return string html attribute or empty string
3425 function disabled( $disabled, $current = true, $echo = true ) {
3426 return __checked_selected_helper( $disabled, $current, $echo, 'disabled' );
3430 * Private helper function for checked, selected, and disabled.
3432 * Compares the first two arguments and if identical marks as $type
3437 * @param mixed $helper One of the values to compare
3438 * @param mixed $current (true) The other value to compare if not just true
3439 * @param bool $echo Whether to echo or just return the string
3440 * @param string $type The type of checked|selected|disabled we are doing
3441 * @return string html attribute or empty string
3443 function __checked_selected_helper( $helper, $current, $echo, $type ) {
3444 if ( (string) $helper === (string) $current )
3445 $result = " $type='$type'";
3456 * Default settings for heartbeat
3458 * Outputs the nonce used in the heartbeat XHR
3462 * @param array $settings
3463 * @return array $settings
3465 function wp_heartbeat_settings( $settings ) {
3467 $settings['ajaxurl'] = admin_url( 'admin-ajax.php', 'relative' );
3469 if ( is_user_logged_in() )
3470 $settings['nonce'] = wp_create_nonce( 'heartbeat-nonce' );