ウィジェットタイトルに画像を入れる

以下をテーマ内のfunction.phpに挿入してください。
[php]
add_filter( ‘widget_title’, ‘img_widget_title’ );
function img_widget_title($title) {
if( preg_match( “/\[\[(.*)\]\]/”, $title, $match ) ) {
$get_title = $match[1];
$get_img_url = clean_url($get_title);
if($get_title == ‘none’) {
$title = ”;
} else {
$get_img_dir = str_replace( get_option(‘home’) . ‘/’, ABSPATH, $get_img_url );
$get_size = getimagesize( $get_img_dir );
$get_alt = preg_replace( “/\[\[(.*)\]\]/”, ”, $title );
$title = ‘' . $get_alt . '‘;
}
return $title;
} else {
return $title;
}
}
[/php]
ウィジェットのタイトルに
タイトル[[画像のURL]]
を入力すると画像が表示されます。
タイトル[[none]]
とするとタイトルは表示されません。

This entry was posted in 未分類. Bookmark the permalink.

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

*

次のHTML タグと属性が使えます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <img localsrc="" alt="">