在网上搜索后,我尝试了很多方法,但从404页的标题中找不到任何东西。如何做,请帮助我
甚至我在404页的页眉中也有这个
if( is_404() ) echo \'404 message goes here | \';
else wp_title( \'|\', true, \'right\' );
我还移动了php标题函数和五个自己的标题,但仍然没有改变为什么?
在网上搜索后,我尝试了很多方法,但从404页的标题中找不到任何东西。如何做,请帮助我
甚至我在404页的页眉中也有这个
if( is_404() ) echo \'404 message goes here | \';
else wp_title( \'|\', true, \'right\' );
我还移动了php标题函数和五个自己的标题,但仍然没有改变为什么?
我会使用wp_title
过滤器挂钩:
function theme_slug_filter_wp_title( $title ) {
if ( is_404() ) {
$title = \'ADD 404 TITLE TEXT HERE\';
}
// You can do other filtering here, or
// just return $title
return $title;
}
// Hook into wp_title filter hook
add_filter( \'wp_title\', \'theme_slug_filter_wp_title\' );
这将很好地与其他插件(例如SEO插件)配合使用,并且将相对向前兼容(changes to document title are coming soon).EDIT
如果您需要覆盖SEO插件过滤器,您可能只需要向add_filter()
呼叫e、 g.如下所示:add_filter( \'wp_title\', \'theme_slug_filter_wp_title\', 11 );
默认值为10
. 数字越小,执行越早(例如,优先级越高),数字越大,执行越晚(例如,优先级越低)。因此,假设您的SEO插件使用默认优先级(即。10
), 只需使用11或更高的数字。wp_title
在WordPress 4.4及更高版本中不推荐使用(see here). 我们现在必须使用document_title_parts 改为过滤器挂钩。以下是已接受的答案,请重新编写以供使用document_title_parts
.
function theme_slug_filter_wp_title( $title_parts ) {
if ( is_404() ) {
$title_parts[\'title\'] = \'ADD 404 TITLE TEXT HERE\';
}
return $title_parts;
}
// Hook into document_title_parts
add_filter( \'document_title_parts\', \'theme_slug_filter_wp_title\' );
以下代码适用于“二十一”主题:
if ( is_404() ) {
echo __(\'Nothing Found\',\'mytheme\')
}
因此标题代码如下所示:<title>
<?php
global $page, $paged;
if ( is_404() ) {
echo __(\'Nothing Found | \',\'mytheme\');
}
else {
wp_title( \'|\', true, \'right\' );
}
?>
</title>
如何更改附件页URL的格式/[post-url]/[attachment-name]/ 到/media/[attachment-name]/? 我知道我可以覆盖get_attachment_link 通过attachment_link 过滤器,但我想我需要更改重定向结构,以便WordPress知道如何处理这些URL?