2014-12-09 3 views
0

나는 아래 기능을 사용하여 wordpress에서 페이지 제목을 변경합니다. 단일 페이지 (page.php)에서 작업하고 있지만 정적 홈 페이지 나 개별 게시물 (single.php)에서는 작동하지 않습니다.Wordpress에서 페이지 제목을 변경하는 기능

전체 사이트에서이 작업을하려면 무엇을 변경해야합니까?

<?php 


function wpse46249_filter_wp_title($title) { 

    $some_custom_title_content = 'This is added to title'; 

    $custom_title = $title . $some_custom_title_content; 

    return $custom_title; 
} 
add_filter('wp_title', 'wpse46249_filter_wp_title'); 
?> 
+0

모든 게시물에 동일한 페이지 제목을 설정 하시겠습니까? –

+0

@HelpingHands, 아니요. 이 코드는 전달 된 원래'$ title'에 무언가를 덧붙이고 있습니다. – rnevius

+0

@ user1609391 ... 이것은 템플릿 문제와 같습니다. – rnevius

답변

0
function wpse46249_filter_wp_title($title) { 

    $some_custom_title_content = 'This is added to title'; 

    $custom_title = $title . $some_custom_title_content; 

    return $custom_title; 
} 
add_filter('the_title', 'wpse46249_filter_wp_title'); 

제목이 wp_posts 테이블에 저장됩니다 유의하시기 바랍니다. 위에 사용 된 필터는 저장되는 모든 새 게시물 제목을 변경합니다. 이 필터는 db에서 가져온 후에 제목을 수정하기 만하면 실제로 db 값을 변경하지 않습니다.

the_title()이 호출 된 페이지에서만 작동합니다.

관련 문제