admin管理员组文章数量:1279008
Hi can anyone help with the below, please?
I want to be able to change the contents of my HTML <title>
tag only, so need to write an if / else statement.
I'm getting myself a bit muddled as my PHP isn't great... but basically something along the lines of the below but combined...
<?php if ( ! is_page_template('boatDetails.php') ) { ?>
<title><?php bloginfo('name'); ?><?php wp_title('|'); ?></title>
<?php } ?>
<?php if ( is_page_template('boatDetails.php') ) { ?>
<title>I'm the boat details page</title>
<?php } ?>
Thanks :)
Hi can anyone help with the below, please?
I want to be able to change the contents of my HTML <title>
tag only, so need to write an if / else statement.
I'm getting myself a bit muddled as my PHP isn't great... but basically something along the lines of the below but combined...
<?php if ( ! is_page_template('boatDetails.php') ) { ?>
<title><?php bloginfo('name'); ?><?php wp_title('|'); ?></title>
<?php } ?>
<?php if ( is_page_template('boatDetails.php') ) { ?>
<title>I'm the boat details page</title>
<?php } ?>
Thanks :)
Share Improve this question edited Aug 20, 2012 at 16:17 Chip Bennett 55.1k8 gold badges90 silver badges170 bronze badges asked Aug 20, 2012 at 16:11 V NealV Neal 2271 gold badge5 silver badges12 bronze badges 5 |2 Answers
Reset to default 5I think you will want to use the wp_title
filter. Add the following to functions.php
:
function wpse62415_filter_wp_title( $title ) {
// Return a custom document title for
// the boat details custom page template
if ( is_page_template( 'boatDetails.php' ) ) {
return 'I\'m the boat details page';
}
// Otherwise, don't modify the document title
return $title;
}
add_filter( 'wp_title', 'wpse62415_filter_wp_title' );
Make no other changes anywhere, including in header.php
.
Add this code to your-page-template.php
file before get_header()
function:
function my_page_title() {
return 'Your value is '; // add dynamic content to this title (if needed)
}
add_filter( 'pre_get_document_title', 'my_page_title' );
本文标签: filtersChanging document title only on a custom page template
版权声明:本文标题:filters - Changing document title only on a custom page template 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741297695a2370912.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
boatDetails.php
? – Chip Bennett Commented Aug 20, 2012 at 16:12header.php
. It just helps us understand/answer the question better. – Chip Bennett Commented Aug 20, 2012 at 16:19