我需要修改输出的<title></title>
标记一些特定的模板,并且必须在php中完成,以便我可以动态地为其生成内容。我一直在玩弄这两段代码,以使其发挥作用,但到目前为止,我唯一得到的变化是重复的标题标记:
remove_filter(\'wp_title\',\'genesis_default_title\', 10, 3);
add_filter(\'wp_title\', \'process_page_titles\', 10, 3);
function process_page_titles($title){
if ( is_page_template( \'landing-page-template.php\' ) ) {
return \'Select Your Car\';
}
elseif( is_page_template( \'dealer-page-template.php\' ) ) {
return \'Select Dealers\';
}
elseif( is_page_template( \'thank-you-page-template.php\' ) ) {
return \'Thank You\';
}
elseif( is_page_template( \'ad-page-template.php\' ) ) {
return \'Deals!\';
}
}
还有这个remove_action(\'genesis_title\',\'genesis_do_title\');
add_action(\'genesis_title\', \'process_page_titles\');
function process_page_titles(){
if ( is_page_template( \'landing-page-template.php\' ) ) {
echo \'<title>\';
wp_title( \'|\',\'Select Car\',\'right\' );
echo \'</title>\';
}
elseif( is_page_template( \'dealer-page-template.php\' ) ) {
echo \'<title>\';
wp_title( \'|\',\'Select Dealer\',\'right\' );
echo \'</title>\';
}
elseif( is_page_template( \'thank-you-page-template.php\' ) ) {
echo \'<title>\';
wp_title( \'|\',\'Thank You\',\'right\' );
echo \'</title>\';
}
elseif( is_page_template( \'ad-page-template.php\' ) ) {
echo \'<title>\';
wp_title( \'|\',\'Deals!\',\'right\' );
echo \'</title>\';
}
else{
echo \'<title>\';
wp_title();
echo \'</title>\';
}
}
这些代码片段将被放置在每个页面模板所需的PHP文件中;因此,无需担心影响其他页面模板,因为它不在功能中。php。