functions.phpを修正する機会は多いと思います。
何かカスタマイズしようとするとfunctions.phpに記述してください、とか多いです。
そこで今回はfunctions.phpの管理方法について書きます。
自分用のfunctions.phpを外出しにする
テーマのデフォルトのfunctions.phpは極力いじりません。
自分で追加するものは外出しにしたファイルに書き込むようにします。
テーマフォルダと同階層でよいのでmyfunctions.phpを作成します。管理画面からはファイルを増やすことが出来ないのでFTPを使うことになります。
myfunctions.phpを作成したらfunctions.phpに以下のコードを追加します。
1 |
require_once locate_template('myfunctions.php'); |
外部ファイルを読み込むコードです。
自分で追加するコードはテーマの編集の右側テンプレートにmyfunctions.phpがあるのでそれを編集します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
<?php function my_getuserdata($atts) { extract(shortcode_atts(array( 'id' => 1, 'property' => 'display_name', ), $atts)); $user = get_userdata($id); if ($property == 'avatar') { $image = get_avatar($id, 150); preg_match("/src='(.*?)'/", $image, $match); return "<img style=\"border-radius:75px;-webkit-border-radius:75px;-moz-border-radius:75px;\" src=\"$match[1]\" width=\"150\" height=\"150\" />"; } else { return $user->get($property); } } add_shortcode('userdata', 'my_getuserdata'); add_filter('widget_text', 'do_shortcode'); function theme_list_categories($output, $args) { $replaced_text = preg_replace('/<\/a> \(([0-9,]*)\)/', ' <span class="count">${1}</span></a>', $output); if($replaced_text != NULL) { return $replaced_text; } else { return $output; } } add_filter('wp_list_categories', 'theme_list_categories', 10, 2); ?> |
こんな感じで。
スポンサーサイト
アフィリエイトはエーハチネット

ドメイン取るならお名前.com
