> php教程 > php手册 > Prepend and Append Text to WordPress?Titles

Prepend and Append Text to WordPress?Titles

WBOY
풀어 주다: 2016-06-06 20:12:51
원래의
1180명이 탐색했습니다.

Read the full article at: Prepend and Append Text to WordPressTitles I was thinking about little ways to improve my blog and one small enhancement I wanted to make was adding more information to?post titles when they?show up in RSS feeds.

Read the full article at: Prepend and Append Text to WordPress Titles

Treehouse
Wufoo

I was thinking about little ways to improve my blog and one small enhancement I wanted to make was adding more information to?post titles when they?show up in RSS feeds. ?Something about notifying the user via title outside of the site itself seemed like a good idea. ?For example, some posts are just small “quick tips”, and more readers may take the time to peruse it quickly because they know it won’t take too long. ?Here’s how I accomplished that feat with WordPress.

The PHP

The first step is creating a function, which is provided the post title and ID, that does a category check and?prepends text accordingly:

function show_as_tip_in_feed($title, $id) {
	if(is_feed() && in_category('tips', $id)) {
		$title = 'Quick Tip: '.$title;
	}
	return $title;
}
로그인 후 복사

Once the function is there, the?add_filter hook?enables the original function:

if(function_exists('add_filter')) {
	add_filter('the_title', 'show_as_tip_in_feed', 10, 2);
}
로그인 후 복사

Of course you don’t need to do the category check or RSS feed check — you can append or prepend text to any and every title, and much like other WordPress functionalities,?the API easily allows developers to do so. ?Win!

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 추천
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿