Created
January 30, 2014 15:05
-
-
Save snoise/8710381 to your computer and use it in GitHub Desktop.
「特定のカテゴリ」の記事のタイトルに文字列を追加してみるwordpressプラグイン
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: paka3 Title Category Add String | |
Plugin URI: http://www.paka3.com/wpplugin | |
Description: 「特定のカテゴリ」の記事のタイトルに文字列を追加してみる | |
Author: Shoji ENDO | |
Version: 0.1 | |
Author URI:http://www.paka3.com/ | |
*/ | |
function paka3_TitleCatAddStr($title, $post_ID){ | |
if(is_single($post_ID) ){ | |
//表示するカテゴリIDを指定する | |
$catID = 13; | |
//一つでも見つかれば離脱 | |
foreach(get_the_category() as $cat){ | |
if($cat->cat_ID == $catID){ | |
$str = "【WordPress1日1プラグイン】"; | |
return $title.$str; | |
} | |
} | |
} | |
//条件に合わない場合はそのまま返す | |
return $title; | |
} | |
add_filter('the_title','paka3_TitleCatAddStr',10,2); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment