初めてのwordpress plugin その1
.勉強がてらwordpressのpluginを作ってみた。
どうやらwordpressのpluginはadd_filterで出力に対してフィルターをかけることが
一つの定番のようです。当初はDBなんかは使わず、出力に対してフィルターをかけることがメインかと思う。
参考にしたのは
http://zone.maple4ever.net/blog/archives/440/
このサイト。
まずは初めてのプラグインということで、Ktai_styleにteltoリンクを追加するものを
作成してみた。ソースは以下の通り。
例えば 0120-000-000
なんかにリンクがつくはず。
<?php /* Plugin Name: Add mobile links Plugin URI: http://www.oganosin.net/ Description: add telto link to the entry Author: oganosin Version: 1.0 Author URI: http://www.oganosin.net */ add_filter('the_content', 'addteltolinks'); function addteltolinks($body) { if(!defined ('KS_VERSION')){ return $body; } $body = preg_replace('/(\d{2,4}\-\d{2,4}\-\d{2,4})/', '<a href="tel:\\1">\\1</a>', $body); return $body; } ?>