我在wordpress网站http://sribasu.com使用了Yootheme模板 该主题基于Warp Framework。我的主题的head.php文件在合并bloginfo名称和wp_title()之后打印页面标题。
不幸的是,wp_title()函数没有生成任何输出。因此,我的所有内页和博客帖页都与主页具有相同的标题。使用此函数时,warp框架是否有任何问题?
我正在使用wordpress 3.6。我一直试图搜索谷歌,看看它是否是一个常见的问题。但是还没有找到有效的解决方案。请帮忙。
编辑: head.php的代码( /yoo_revista_wp/warp/systems/wordpress/layouts/head.php )如下:
<meta charset="<?php bloginfo('charset'); ?>" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<?php if($this['config']->get('responsive', false)): ?>
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php endif; ?>
<title><?php bloginfo('name'); ?> <?php wp_title(); ?></title>
<link rel="shortcut icon" href="<?php echo $this['path']->url('template:favicon.ico');?>" />
<link rel="apple-touch-icon-precomposed" href="<?php echo $this['path']->url('template:apple_touch_icon.png'); ?>" />
<?php
wp_enqueue_script('jquery');
wp_head();
// set body classes
$this['config']->set('body_classes', implode(' ', get_body_class($this['config']->get('body_classes'))));
// get styles and scripts
$styles = $this['asset']->get('css');
$scripts = $this['asset']->get('js');
// compress styles and scripts
if ($compression = $this['config']->get('compression')) {
$options = array();
$filters = array('CSSImportResolver', 'CSSRewriteURL', 'CSSCompressor');
// set options
if ($compression == 3) {
$options['Gzip'] = true;
}
// set filter
if ($compression >= 2 && ($this['useragent']->browser() != 'msie' || version_compare($this['useragent']->version(), '8.0', '>='))) {
$filters[] = 'CSSImageBase64';
}
if ($styles) {
// cache styles and check for remote styles
$styles = array($this['asset']->cache('template.css', $styles, $filters, $options));
foreach ($styles[0] as $style) {
if ($style->getType() == 'File' && !$style->getPath()) {
$styles[] = $style;
}
}
}
if ($scripts) {
// cache scripts and check for remote scripts
$scripts = array($this['asset']->cache('template.js', $scripts, array('JSCompressor'), $options));
foreach ($scripts[0] as $script) {
if ($script->getType() == 'File' && !$script->getPath()) {
$scripts[] = $script;
}
}
}
}
// add styles
if ($styles) {
foreach ($styles as $style) {
if ($url = $style->getUrl()) {
printf("<link rel=\"stylesheet\" href=\"%s\" />\n", $url);
} else {
printf("<style>%s</style>\n", $style->getContent());
}
}
}
// add scripts
if ($scripts) {
foreach ($scripts as $script) {
if ($url = $script->getUrl()) {
printf("<script src=\"%s\"></script>\n", $url);
} else {
printf("<script>%s</script>\n", $script->getContent());
}
}
}
// add feed link
if (strlen($this['config']->get('rss_url',''))) {
printf("<link href=\"%s\" rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS 2.0\" />\n", $this['config']->get('rss_url'));
}
$this->output('head');
答案 0 :(得分:0)
来自codex:
主题不应结合使用wp_title()函数 与其他字符串或函数(如连接 bloginfo('name'))写入元素的内容,因为 它会使插件无法重写整个标题,以防万一 插件使用wp_title过滤器做重写,这是最好的 实践。现在使用此功能是主题的要求 开发者。
测试代码:
<?php bloginfo('name'); ?><?php wp_title('»'); ?>
第一个参数$ sep:在帖子标题(即分隔符)之前或之后(由$ seplocation指定)显示的文本。 默认值:»(»)
答案 1 :(得分:0)
我必须承认,Ben的回答得到了很好的线索。最后确定了罪魁祸首插件 - 它是Contus Video Gallery。该插件的功能很好,但篡改了我的页面标题:X
我在 /plugins/contus-video-gallery/hdflvvideoshare.php 中的Contus Video Gallery插件中修复了wp_title过滤器功能,它就像一个魅力!
function add_video_title() {
global $wpdb;
$videoID = url_to_custompostid(get_permalink());
if (isset($_GET['p'])) {
$videoID = intval($_GET['p']);
}
if (isset($_GET['playid'])) {
$playId = intval($_GET['playid']);
}
if (!empty($videoID)) {
$videoID = $wpdb->get_var("SELECT vid FROM " . $wpdb->prefix . "hdflvvideoshare WHERE slug='" . intval($videoID) . "'");
$video_title = $wpdb->get_var("SELECT t1.name"
. " FROM " . $wpdb->prefix . "hdflvvideoshare AS t1"
. " WHERE t1.publish='1' AND t1.vid='" . intval($videoID) . "' LIMIT 1");
}
if (!empty($playId)) {
$video_title = $wpdb->get_var("SELECT t1.playlist_name AS name"
. " FROM " . $wpdb->prefix . "hdflvvideoshare_playlist AS t1"
. " WHERE t1.is_publish='1' AND t1.pid='" . intval($playId) . "' LIMIT 1");
}
if (!empty($video_title))
echo $video_title;
}
function add_video_title($title) {
if($_REQUEST['post_type']!='videogallery'){
return $title;
}
global $wpdb;
$videoID = url_to_custompostid(get_permalink());
if (isset($_GET['p'])) {
$videoID = intval($_GET['p']);
}
if (isset($_GET['playid'])) {
$playId = intval($_GET['playid']);
}
if (!empty($videoID)) {
$videoID = $wpdb->get_var("SELECT vid FROM " . $wpdb->prefix . "hdflvvideoshare WHERE slug='" . intval($videoID) . "'");
$video_title = $wpdb->get_var("SELECT t1.name"
. " FROM " . $wpdb->prefix . "hdflvvideoshare AS t1"
. " WHERE t1.publish='1' AND t1.vid='" . intval($videoID) . "' LIMIT 1");
}
if (!empty($playId)) {
$video_title = $wpdb->get_var("SELECT t1.playlist_name AS name"
. " FROM " . $wpdb->prefix . "hdflvvideoshare_playlist AS t1"
. " WHERE t1.is_publish='1' AND t1.pid='" . intval($playId) . "' LIMIT 1");
}
if (!empty($video_title))
return $video_title;
}