Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Use a filter for wp_title instead of hard-coding things in header.php #79

Merged
merged 2 commits into from over 1 year ago

2 participants

Konstantin Kovshenin Konstantin Obenland
Konstantin Kovshenin
Collaborator

Let's try this again... Instead of hard-coding things like blog name, description and page number in the header.php template, use a simple call to wp_title() and make the rest in tweaks.php using the wp_title filter. This allows others to easily override the tag without having to parse the output from buffer. SEO plugins will love this.

For previous discussions see #33

Konstantin Obenland obenland merged commit ba4af12 into from
Konstantin Obenland obenland closed this
marksantiago marksantiago referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
2  functions.php
@@ -34,7 +34,7 @@ function _s_setup() {
34 34
 	/**
35 35
 	 * Custom functions that act independently of the theme templates
36 36
 	 */
37  
-	//require( get_template_directory() . '/inc/tweaks.php' );
  37
+	require( get_template_directory() . '/inc/extras.php' );
38 38
 
39 39
 	/**
40 40
 	 * Custom Theme Options
24  header.php
@@ -12,27 +12,7 @@
12 12
 <head>
13 13
 <meta charset="<?php bloginfo( 'charset' ); ?>" />
14 14
 <meta name="viewport" content="width=device-width" />
15  
-<title><?php
16  
-	/*
17  
-	 * Print the <title> tag based on what is being viewed.
18  
-	 */
19  
-	global $page, $paged;
20  
-
21  
-	wp_title( '|', true, 'right' );
22  
-
23  
-	// Add the blog name.
24  
-	bloginfo( 'name' );
25  
-
26  
-	// Add the blog description for the home/front page.
27  
-	$site_description = get_bloginfo( 'description', 'display' );
28  
-	if ( $site_description && ( is_home() || is_front_page() ) )
29  
-		echo " | $site_description";
30  
-
31  
-	// Add a page number if necessary:
32  
-	if ( $paged >= 2 || $page >= 2 )
33  
-		echo ' | ' . sprintf( __( 'Page %s', '_s' ), max( $paged, $page ) );
34  
-
35  
-	?></title>
  15
+<title><?php wp_title( '|', true, 'right' ); ?></title>
36 16
 <link rel="profile" href="http://gmpg.org/xfn/11" />
37 17
 <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
38 18
 <!--[if lt IE 9]>
@@ -59,4 +39,4 @@
59 39
 		</nav><!-- .site-navigation .main-navigation -->
60 40
 	</header><!-- #masthead .site-header -->
61 41
 
62  
-	<div id="main" class="site-main">
  42
+	<div id="main" class="site-main">
29  inc/tweaks.php → inc/extras.php
@@ -49,4 +49,31 @@ function _s_enhanced_image_navigation( $url, $id ) {
49 49
 
50 50
 	return $url;
51 51
 }
52  
-add_filter( 'attachment_link', '_s_enhanced_image_navigation', 10, 2 );
  52
+add_filter( 'attachment_link', '_s_enhanced_image_navigation', 10, 2 );
  53
+
  54
+/**
  55
+ * Filters wp_title to print a neat <title> tag based on what is being viewed.
  56
+ *
  57
+ * @since _s 1.1
  58
+ */
  59
+function _s_wp_title( $title, $sep ) {
  60
+	global $page, $paged;
  61
+
  62
+	if ( is_feed() )
  63
+		return $title;
  64
+
  65
+	// Add the blog name
  66
+	$title .= get_bloginfo( 'name' );
  67
+
  68
+	// Add the blog description for the home/front page.
  69
+	$site_description = get_bloginfo( 'description', 'display' );
  70
+	if ( $site_description && ( is_home() || is_front_page() ) )
  71
+		$title .= " $sep $site_description";
  72
+
  73
+	// Add a page number if necessary:
  74
+	if ( $paged >= 2 || $page >= 2 )
  75
+		$title .= " $sep " . sprintf( __( 'Page %s', '_s' ), max( $paged, $page ) );
  76
+
  77
+	return $title;
  78
+}
  79
+add_filter( 'wp_title', '_s_wp_title', 10, 2 );
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.