Permalink
Browse files

Change tarski_doctitle to a filter on wp_title.

  • Loading branch information...
1 parent 628431a commit fe543c2508a547876a43abcf6334c6100c57ad3d @beastaugh committed Jan 31, 2012
Showing with 95 additions and 34 deletions.
  1. +53 −0 app/api/deprecated.php
  2. +1 −0 functions.php
  3. +1 −1 header.php
  4. +40 −33 library/helpers/template_helper.php
@@ -12,6 +12,59 @@
*/
/**
+ * Returns the document title.
+ *
+ * The order (site name first or last) can be set on the Tarski Options page.
+ * While the function ultimately returns a string, please note that filters
+ * are applied to an array! This allows plugins to easily alter any aspect
+ * of the title. For example, one might write a plugin to change the separator.
+ *
+ * @since 1.5
+ * @deprecated 3.2.0
+ *
+ * @param string $sep
+ * @return string
+ *
+ * @hook filter tarski_doctitle
+ * Filter document titles.
+ */
+function tarski_doctitle($sep = '·') {
+ _deprecated_function('wp_title', '3.2.0');
+
+ $site_name = get_bloginfo('name');
+ $content = trim(wp_title('', false));
+
+ if (is_404())
+ $content = sprintf(__('Error %s', 'tarski'), '404');
+ elseif ((get_option('show_on_front') == 'posts') && is_home())
+ $content = get_bloginfo('description', 'display');
+ elseif (is_search())
+ $content = sprintf(__('Search results for %s', 'tarski'), esc_html(get_search_query()));
+ elseif (is_month())
+ $content = single_month_title(' ', false);
+ elseif (is_tag())
+ $content = multiple_tag_titles();
+
+ $elements = strlen($content) > 0
+ ? array('site_name' => $site_name,
+ 'separator' => $sep,
+ 'content' => $content)
+ : array('site_name' => $site_name);
+
+ if (get_tarski_option('swap_title_order'))
+ $elements = array_reverse($elements, true);
+
+ // Filters should return an array
+ $elements = apply_filters('tarski_doctitle', $elements);
+
+ // But if they don't, it won't try to implode
+ if (is_array($elements))
+ $doctitle = implode(' ', $elements);
+
+ echo $doctitle;
+}
+
+/**
* If debug mode is enabled, use uncompressed (development mode) JavaScript.
*
* @since 2.7
View
@@ -182,6 +182,7 @@
add_action('wp_head', 'tarski_meta', 9);
add_action('wp_head', 'tarski_stylesheets', 9);
add_filter('gallery_style', 'trim_gallery_style', 20);
+add_filter('wp_title', 'tarski_document_title', 10, 3);
add_action('th_header', 'tarski_headerimage');
add_action('th_header', 'tarski_titleandtag');
View
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html <?php language_attributes('html'); ?>><head>
<meta http-equiv="Content-Type" content="<?php echo get_bloginfo('html_type') .'; charset=' . get_bloginfo('charset'); ?>">
- <title><?php echo tarski_doctitle(); ?></title>
+ <title><?php echo wp_title('&middot;'); ?></title>
<?php wp_head(); ?>
</head>
@@ -33,7 +33,7 @@ function _tarski_get_alternate_stylesheet_uri() {
}
/**
- * Returns the document title.
+ * Creates the document title.
*
* The order (site name first or last) can be set on the Tarski Options page.
* While the function ultimately returns a string, please note that filters
@@ -48,38 +48,45 @@ function _tarski_get_alternate_stylesheet_uri() {
* @hook filter tarski_doctitle
* Filter document titles.
*/
-function tarski_doctitle($sep = '&middot;') {
- $site_name = get_bloginfo('name');
- $content = trim(wp_title('', false));
-
- if (is_404())
- $content = sprintf(__('Error %s', 'tarski'), '404');
- elseif ((get_option('show_on_front') == 'posts') && is_home())
- $content = get_bloginfo('description', 'display');
- elseif (is_search())
- $content = sprintf(__('Search results for %s', 'tarski'), esc_html(get_search_query()));
- elseif (is_month())
- $content = single_month_title(' ', false);
- elseif (is_tag())
- $content = multiple_tag_titles();
-
- $elements = strlen($content) > 0
- ? array('site_name' => $site_name,
- 'separator' => $sep,
- 'content' => $content)
- : array('site_name' => $site_name);
-
- if (get_tarski_option('swap_title_order'))
- $elements = array_reverse($elements, true);
-
- // Filters should return an array
- $elements = apply_filters('tarski_doctitle', $elements);
-
- // But if they don't, it won't try to implode
- if (is_array($elements))
- $doctitle = implode(' ', $elements);
-
- echo $doctitle;
+function tarski_document_title($title, $sep, $seplocation) {
+ $title = trim($title);
+ $sitename = get_bloginfo('name');
+ $enc = get_option('blog_charset');
+
+ if (!(isset($enc) && strlen($enc) > 0)) {
+ $enc = "utf-8";
+ }
+
+ $slen = mb_strlen($sep, $enc);
+ $tlen = mb_strlen($title, $enc);
+
+ if ($seplocation == 'right') {
+ $doctitle = mb_substr($title, 0, $tlen - $slen, $enc);
+ } else {
+ $doctitle = mb_substr($title, $slen, $tlen - $slen, $enc);
+ }
+
+ $doctitle = trim($doctitle);
+
+ if (is_404()) {
+ $doctitle = sprintf(__('Error %s', 'tarski'), '404');
+ } elseif ((get_option('show_on_front') == 'posts') && is_home()) {
+ $doctitle = get_bloginfo('description', 'display');
+ } elseif (is_search()) {
+ $doctitle = sprintf(__('Search results for %s', 'tarski'), esc_html(get_search_query()));
+ } elseif (is_month()) {
+ $doctitle = single_month_title(' ', false);
+ } elseif (is_tag()) {
+ $doctitle = multiple_tag_titles();
+ }
+
+ $title = array($sitename, $sep, $doctitle);
+
+ if (get_tarski_option('swap_title_order')) {
+ $title = array_reverse($title);
+ }
+
+ return implode(" ", $title);
}
/**

0 comments on commit fe543c2

Please sign in to comment.