Skip to content

Instantly share code, notes, and snippets.

@snoise
Created January 30, 2014 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snoise/8710381 to your computer and use it in GitHub Desktop.
Save snoise/8710381 to your computer and use it in GitHub Desktop.
「特定のカテゴリ」の記事のタイトルに文字列を追加してみるwordpressプラグイン
<?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