Nhiều khi làm web chúng ta có nhiều bài viết ko muốn cho khách xem được lên để post_status là Private hoặc Protected . Nhưng điều không hay lắm là khi hiển thị tiêu đề bài viết bằng the_title() thì tiêu đề lại có dạng Private: <tiêu_đề> hoặc Protected: <tiêu_đề>. Rõ là xấu phải không?
Code sau đây sẽ giúp bạn xóa được chữ đó đi.
Remove Private Protected from Post Titles
thêm 1 trong các đoạn code sau vào file functions.php trong theme của bạn là được
Code 1:
function the_title_trim($title) { $pattern[0] = '/Protected:/'; $pattern[1] = '/Private:/'; $replacement[0] = ''; // Enter some text to put in place of Protected: $replacement[1] = ''; // Enter some text to put in place of Private: return preg_replace($pattern, $replacement, $title); } add_filter('the_title', 'the_title_trim');
C0de 2:
function the_title_trim($title) { $title = attribute_escape($title); $findthese = array( '#Protected:#', '#Private:#' ); $replacewith = array( '', // What to replace "Protected:" with '' // What to replace "Private:" with ); $title = preg_replace($findthese, $replacewith, $title); return $title; } add_filter('the_title', 'the_title_trim');
Code 3:
Code này ngắn gọn nhất ^^
function title_format($content) { return '%s'; } add_filter('private_title_format', 'title_format'); add_filter('protected_title_format', 'title_format');
Chúc các bạn thành công^^
- Bình luận