サポート » プラグイン » カスタム投稿(custom post)のアーカイブ(archive)ページにHTML付きの説明0t 文を掲示したい

  • 解決済 taka_fumi

    (@taka_fumi)


    It is a question.
    I created an archive page of custom post type created by Custom Post Type UI.
    However, if you display custom post type description fields on this archive page, they will all be displayed in plain text.
    Is there a way to use HTML line breaks (<br>)?

    質問です。
    私はカスタム投稿タイプUIで作成したカスタム投稿タイプのアーカイブページを作成しました。
    ただし、このアーカイブページにカスタム投稿タイプの説明フィールドを表示すると、それらはすべてプレーンテキストで表示されます。
    HTMLの改行を使用する方法はありますか(<br>)。

4件の返信を表示中 - 1 - 4件目 (全4件中)
  • ishitaka

    (@ishitaka)

    こんにちは

    説明文の表示は、テーマのデフォルトの状態で表示されているのでしょうか、それともテーマをカスタマイズして表示させているのでしょうか?
    テーマのデフォルトの場合はテーマ名を、カスタマイズしている場合はそのコードを教えてもらえますか。

    なお、the_archive_description()、get_the_archive_description() などの関数で表示している場合は、WordPress のデフォルトの状態で、br タグはそのまま出力されます。また改行は br タグになります。これらの関数を使用していてタグが削除されるようであれば、プラグイン(PS Disable Auto Formatting など)によって削除されているのかもしれません。プラグインを停止するなどして試してみてはと思います。

    トピック投稿者 taka_fumi

    (@taka_fumi)

    返信、ありがとうございます。

    使っているテーマは「libretto」のchildで、デフォルトのarchive.phpを以下のようにカスタマイズしています。

    <?php get_header(); ?>
    <section id="primary" class="content-area">
    	<div id="content" class="site-content" role="main">
    
    <!-- ページの抜粋文 -->
    <p style="margin-top:-2em; margin-bottom:2em; ">
    	<?php if( is_archive() && !is_paged() ) : ?>
    		<?php 
    		$post_type = get_queried_object();
    		echo esc_attr($post_type->description);
    	?>
    	<?php else: ?>
    	<?php endif; ?>
    </p>
    <!-- Pを外す -->
    	<?php remove_filter('description', 'wpautop'); ?>
    
    <div style="text-align:center"><?php wp_pagenavi(); ?></div><!-- PageNavi -->
    
    <?php if(have_posts()): while(have_posts()): the_post(); ?>
    <div class="events_contents">
     
    <ul>
    

    それとfunction.phpに以下を記載しています。

    
    //ビジュアルからテキストにしてHTMLタグが消えたので対処:20190420
    function customKsesAllowedHtml( $tags, $context ) {
        if ( $context == 'post' ) {
            $tags['script'] = true;
            $tags['button'] = array(
                'data-*'=>true,
                'class'=>true
            );
            $tags['div'] = array(
                'data-*'=>true,
                'class'=>true,
                'id'=>true
            );
        }
        return $tags;
    }
    
    //固定ページの本文と抜粋だけ「p」を消す
    if (!function_exists('rewpautop')) {
        add_action('wp', 'rewpautop');
        function rewpautop() {
            if (!is_page()) {
                add_filter('the_content', 'wpautop');
            }
        }
    }

    また、PS Disable Auto Formattingは使いましたが、やはり平文で表示されるので今は削除してあります。
    phpはよく分かっていないなか、いろいろなサイトからの情報を切り張りで使っているので、どこに問題があるのか分からなくて。
    よろしくお願い申し上げます。

    ishitaka

    (@ishitaka)

    下記のようにするはどうでしょうか?

    echo esc_attr($post_type->description);

    echo wptexturize( $post_type->description );

    または

    echo wpautop( wptexturize( $post_type->description ) );

    トピック投稿者 taka_fumi

    (@taka_fumi)

    早速ありがとうございます。

    
    echo wptexturize( $post_type->description );
    

    に換えて、説明欄で br を記載して、無事改行されるようになりました。
    本当に助かりました!!

4件の返信を表示中 - 1 - 4件目 (全4件中)
  • トピック「カスタム投稿(custom post)のアーカイブ(archive)ページにHTML付きの説明0t 文を掲示したい」には新たに返信することはできません。