人力検索はてな
モバイル版を表示しています。PC版はこちら
i-mobile

wordpress3.5に関して質問です。タグやカテゴリーの説明文にHTMLのタグを使う事を検討しています。対応方法、もしくはプラグインがあればご教授頂ければと思います。

●質問者: mkusume
●カテゴリ:ウェブ制作
○ 状態 :終了
└ 回答数 : 1/1件

▽最新の回答へ

1 ● rouge_2008
●190ポイント ベストアンサー

テーマの「functions.php」に次の記述を追加します。

function allow_html_description() {
remove_filter('pre_term_description', 'wp_filter_kses');
}
add_action('admin_init', 'allow_html_description');


http://yasada.biz/2008/wordpress_category_description/
※バージョンが違うので行数や記述方法が違いますが、3.5でも同じ処理を行っています。

WordPress2.3の場合

2.3の場合、編集するファイルは同じdefault-filters.phpですが、編集する場所が変わります。

14行目付近にある

[source='php']
// Kses only for textarea saves

$filters = array(‘pre_term_description’, ‘pre_link_description’, ‘pre_link_notes’, ‘pre_user_description’);
foreach ( $filters as $filter ) {
add_filter($filter, ‘wp_filter_kses’);
}
[/source]

という部分において、
[source='php']
// add_filter($filter, ‘wp_filter_kses’);
[/source]
とコメントアウトすればOKです。



http://ja.forums.wordpress.org/topic/1860

add_filter() されたフィルターは remove_filter() で取り除けます。したがって、プラグインで実行するならば、当該のフィルターを remove_filter() すればよいです。



※あるいは別の方法として、許可するタグを定義する事でも対応可能です。(こちらも「functions.php」に記述します。)

function custom_allowed_tags($text) {
global $allowedtags;
$allowedtags = array(
'a' => array(
'href' => true,
'title' => true,
),
'blockquote' => array(
'cite' => true,
),
'cite' => array(),
'code' => array(),
'del' => array(
'datetime' => true,
),
'div' => array(
'class' => true,
'id' => true,
),
'em' => array(),
'p' => array(
'class' => true,
'id' => true,
),
'span' => array(
'class' => true,
'id' => true,
),
'strong' => array(),
);
return $text;
}
add_action('pre_term_description', 'custom_allowed_tags', 1);


※カテゴリーやタグのディスクリプションでデフォルトで許可されているHTMLタグ「$allowedtags」は、「wp-includes/kses.php」(※371行目以降)で確認できますので、書き方の参考にしてください。(許可するHTMLタグと属性を個別に指定します。)


mkusumeさんのコメント
いつもありがとうございます。確認します。

mkusumeさんのコメント
確認しました。本当にいつもありがとうございます。
関連質問

●質問をもっと探す●



0.人力検索はてなトップ
8.このページを友達に紹介
9.このページの先頭へ
対応機種一覧
お問い合わせ
ヘルプ/お知らせ
ログイン
無料ユーザー登録
はてなトップ