在客户网站上工作:http://tinyurl.com/lc4ewwf
我没有创建这个模板,我的客户希望我删除子页面上发生的双重标题。问题是,我无法弄清楚导致这种情况发生的原因。主页上也没有发生这种情况。也没有安装SEO脚本。
这就是header.php的样子
<?php
/**
* The Header for our theme.
*
* Displays all of the <head> section and everything up till <div id="main">
*
* @package WordPress
* @subpackage Twenty_Ten
* @since Twenty Ten 1.0
*/
?><!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<title><?php
/*
* Print the <title> tag based on what is being viewed.
*/
global $page, $paged;
wp_title( '|', true, 'right' );
// Add the blog name.
bloginfo( 'name' );
// Add the blog description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) )
echo " | $site_description";
// Add a page number if necessary:
if ( $paged >= 2 || $page >= 2 )
echo ' | ' . sprintf( __( 'Page %s', 'twentyten' ), max( $paged, $page ) );
?><?php echo get_the_title($ID); ?></title>
<link rel="profile" href="http://gmpg.org/xfn/11" />
<?php /*?><link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url' ); ?>" /><?php */?>
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
<?php
/* We add some JavaScript to pages with the comment form
* to support sites with threaded comments (when in use).
*/
if ( is_singular() && get_option( 'thread_comments' ) )
wp_enqueue_script( 'comment-reply' );
/* Always have wp_head() just before the closing </head>
* tag of your theme, or you will break many plugins, which
* generally use this hook to add elements to <head> such
* as styles, scripts, and meta tags.
*/
wp_head();
?>
<!-- Styles -->
<link href="<?php bloginfo('template_url'); ?>/css/bootstrap.css" rel="stylesheet">
<link href="<?php bloginfo('template_url'); ?>/css/bootstrap-responsive.css" rel="stylesheet">
<link href="<?php bloginfo('template_url'); ?>/css/styles.css" rel="stylesheet">
<link href="<?php bloginfo('template_url'); ?>/css/wordpress.css" rel="stylesheet">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!-- Favorite Icons -->
<link rel="shortcut icon" href="<?php bloginfo('template_url'); ?>/images/favicon.ico">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="<?php bloginfo('template_url'); ?>/images/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="<?php bloginfo('template_url'); ?>/images/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="<?php bloginfo('template_url'); ?>/images/apple-touch-icon-57-precomposed.png">
<!-- TypeKit -->
<script type="text/javascript" src="http://use.typekit.com/zlf3uad.js"></script>
<script type="text/javascript">try{Typekit.load();}catch(e){}</script>
<!-- For slideshow -->
</head>
<body>
我只是疯了而且忽略了什么?
答案 0 :(得分:3)
wp_title( '|', true, 'right' );
和
echo get_the_title($ID);
输出标题;因此你有两个头衔。
尝试通过 functions.php 将其连接到wp_title函数:
function my_wp_title( $title, $sep ) {
global $paged, $page;
if ( is_feed() ) {
return $title;
}
// Add the site name.
$title .= get_bloginfo( 'name', 'display' );
// Add the site description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) ) {
$title = "$title $sep $site_description";
}
// Add a page number if necessary.
if ( $paged >= 2 || $page >= 2 ) {
$title = "$title $sep " . sprintf( __( 'Page %s', 'textdomain' ), max( $paged, $page ) );
}
return $title;
}
add_filter( 'wp_title', 'my_wp_title', 10, 2 );
并使用标题中的函数:
<title><?php wp_title(); ?></title>
答案 1 :(得分:2)
你有两个看起来像是重复的电话。在<title>
标记的PHP块中,您正在调用:
wp_title( '|', true, 'right' );
Accord to the documentation,这将返回帖子的标题。
然后,在你的PHP阻止之后,你正在呼叫:
echo get_the_title($ID)
完全相同的事情。