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

以下をテーマ内のfunction.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 = '<img src="' . $get_img_url . '" alt="' . $get_alt . '" ' . $get_size[3] . ' />';
		}
		return $title;
	} else {
		return $title;
	}
}

ウィジェットのタイトルに
タイトル[[画像のURL]]
を入力すると画像が表示されます。
タイトル[[none]]
とするとタイトルは表示されません。

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

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

  1. [...] Webnist Code Just another Webnist(うぇぶにすと) Blog Sites site 内容をスキップ ホーム紹介 ← ウィジェットタイトルに画像を入れる [...]

コメントを残す

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

*

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