Title: function.php と　特定のプラグインとのコンフリクトの解決法
Last modified: 2021年8月20日

---

# function.php と　特定のプラグインとのコンフリクトの解決法

 *  解決済 [mrsmith11](https://ja.wordpress.org/support/users/mrsmith11/)
 * (@mrsmith11)
 * [5年、 2ヶ月前](https://ja.wordpress.org/support/topic/function-php-%e3%81%a8%e3%80%80%e7%89%b9%e5%ae%9a%e3%81%ae%e3%83%97%e3%83%a9%e3%82%b0%e3%82%a4%e3%83%b3%e3%81%a8%e3%81%ae%e3%82%b3%e3%83%b3%e3%83%95%e3%83%aa%e3%82%af%e3%83%88%e3%81%ae%e8%a7%a3/)
 * 解決法がわからないので、質問させてください。
 * 「Rich table of content」
    [https://ja.wordpress.org/plugins/rich-table-of-content/](https://ja.wordpress.org/plugins/rich-table-of-content/)
 * という目次生成プラグインを使用を使用しているのですが、目次が正常に生成されません。
 * （本来は自動で生成される目次が生成されなかったり、なぜか別の記事の目次が表示さ
   れたり）
 * ※作者にも問い合わせましたが、返信はきませんでした。
    ※サポートフォーラムも死んで
   います。
 * 原因はわかっています。
 * カスタムのブログカード用のコードをfunction.phpで記述して使用しているからです。
 *     ```
       //---------------------------------------//
       // 内部リンクのブログカード化（ショートコード）
       // ここから
       //---------------------------------------//
   
       // 記事IDを指定して抜粋文を取得する
       function ltl_get_the_excerpt( $post_id ){
         global $post;
         $post_bu = $post;
         $post = get_post( $post_id );
         setup_postdata( $post_id );
         $output = get_the_excerpt();
         $post = $post_bu;
         return $output;
       }
   
       //内部リンクをはてなカード風にするショートコード
       function nlink_scode( $atts ) {
           extract(shortcode_atts(array(
               'url'=>"",
               'title'=>"",
               'excerpt'=>""
           ),$atts));
   
           $id = url_to_postid( $url );//URLから投稿IDを取得
   
           $img_width ="200";//画像サイズの幅指定
           $img_height = "200";//画像サイズの高さ指定
           $no_image = 'noimageに指定したい画像があればここにパス'; //アイキャッチ画像がない場合の画像（絶対パス）を指定
   
         //自サイト名を表示させたい場合はここにアイコン画像（絶対パス）を指定
         //サイズは 1:1 推奨
         //表示させない場合はそのまま未入力で
         $site_icon = '';
   
           //タイトルを取得
           if( empty( $title ) ){
               $title = esc_html(get_the_title( $id ));
           }
   
         //抜粋文を取得
           if( empty( $excerpt ) ){
               $excerpt = esc_html( ltl_get_the_excerpt( $id ) );
           if( mb_strlen($excerpt, 'UTF-8') > 40 ){
               $excerpt= mb_substr($excerpt, 0, 40, 'UTF-8').'.....';
           }
           }
   
         //サイト名を取得
         if( $site_icon != "" ){
               $site = '<img src="' . $site_icon . '" alt="' . get_bloginfo( 'name' ) . '">' . get_bloginfo( 'name' );
           }
   
           //アイキャッチ画像を取得
           if( has_post_thumbnail( $id ) ) {
             $img = wp_get_attachment_image_src( get_post_thumbnail_id( $id ),array( $img_width, $img_height ) );
             $img_tag = "<img src='" . $img[0] . "' alt='{$title}' width=" . $img[1] . " height=" . $img[2] . " />";
           }else{
             $img_tag ='<img src="'.$no_image.'" alt="" width="'.$img_width.'" height="'.$img_height.'" />';
           }
   
           $nlink .='
       <a href="'. $url .'" class="tmt-blog-card">
         <div class="tmt-blog-card-box">
           <div class="tmt-blog-card-thumbnail">'. $img_tag .'</div>
           <div class="tmt-blog-card-content">
               <div class="tmt-blog-card-title">'. $title .' </div>
               <div class="tmt-blog-card-excerpt">'. $excerpt .'</div>
           </div>
         </div>
         <div class="tmt-blog-card-site">'. $site .'</div>
       </a>';
   
           return $nlink;
       }
   
       add_shortcode("nlink", "nlink_scode");
       //---------------------------------------//
       // ここまで
       // 内部リンクのブログカード化（ショートコード）
       //---------------------------------------//
       ```
   
 * このブログカード用のfunction.phpの記述が、「Rich table of content」プラグイン
   とコンフリクトを起こしており、目次が自動表示されなかったり、投稿の編集を行って
   も目次が更新されなかったり、別の記事の目次が表示されたりします。
 * どうやら、このブログカードを呼び出すショートコード
 * `[nlink url="https://example.com" title="サイトタイトルサイトタイトルサイトタイトル"
   excerpt="説明文説明文説明文説明文説明文説明文説明文説明文説明文説明文説明文説明
   文説明文説明文"]`
 * を使用した記事だけ目次の表示がおかしいみたいです。
 * どなたか知識のある方、よろしければ解決法をお教えいただけないでしょうか。
 * どのように修正すれば目次プラグインが正常に動作するかお教えいただければ幸いでご
   ざいます。
 * この目次プラグインが業界一美しく、どうしてもこのまま使い続けたいです。
 * お忙しいところ恐れ入りますが、このエラーの解決方法をお教えください。
    よろしく
   お願いいたします。
 * 使用テーマ
    Blogghiamoバージョン: 1.9.0 作者: Rizzo Andrea – CrestaProject.com
 * wordpress 5.8
    php 7.4.21

2件の返信を表示中 - 1 - 2件目 (全2件中)

 *  [Aki Hamano](https://ja.wordpress.org/support/users/wildworks/)
 * (@wildworks)
 * [5年、 2ヶ月前](https://ja.wordpress.org/support/topic/function-php-%e3%81%a8%e3%80%80%e7%89%b9%e5%ae%9a%e3%81%ae%e3%83%97%e3%83%a9%e3%82%b0%e3%82%a4%e3%83%b3%e3%81%a8%e3%81%ae%e3%82%b3%e3%83%b3%e3%83%95%e3%83%aa%e3%82%af%e3%83%88%e3%81%ae%e8%a7%a3/#post-11673999)
 * [@mrsmith11](https://ja.wordpress.org/support/users/mrsmith11/)さん
 * はじめまして。
    実際に試したわけではないですが、`ltl_get_the_excerpt`関数の処理
   がよろしくないので、そのプラグインに影響を与えているように思います。
 * 以下のような記述で対応出来ないでしょうか。
 *     ```
       function ltl_get_the_excerpt( $post_id ){
       	$post = get_post( $post_id );
       	if ( empty( $post->post_excerpt ) ) {
       		return wp_html_excerpt( strip_shortcodes( $post->post_content ), 55, '...' );
       	} else {
       		return $post->post_excerpt;
       	}
       }
       ```
   
 *  トピック投稿者 [mrsmith11](https://ja.wordpress.org/support/users/mrsmith11/)
 * (@mrsmith11)
 * [5年、 2ヶ月前](https://ja.wordpress.org/support/topic/function-php-%e3%81%a8%e3%80%80%e7%89%b9%e5%ae%9a%e3%81%ae%e3%83%97%e3%83%a9%e3%82%b0%e3%82%a4%e3%83%b3%e3%81%a8%e3%81%ae%e3%82%b3%e3%83%b3%e3%83%95%e3%83%aa%e3%82%af%e3%83%88%e3%81%ae%e8%a7%a3/#post-11674000)
 * ありがとうございます！頂いたコードを置き換えることで、正常に目次が表示されました！
 * ありがとうございました！

2件の返信を表示中 - 1 - 2件目 (全2件中)

 トピック「function.php と　特定のプラグインとのコンフリクトの解決法」には新たに
返信することはできません。

 * フォーラム: [使い方全般](https://ja.wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2件の返信
 * 2人の参加者
 * 最後の返信者: [mrsmith11](https://ja.wordpress.org/support/users/mrsmith11/)
 * 最後の活動: [5年、 2ヶ月前](https://ja.wordpress.org/support/topic/function-php-%e3%81%a8%e3%80%80%e7%89%b9%e5%ae%9a%e3%81%ae%e3%83%97%e3%83%a9%e3%82%b0%e3%82%a4%e3%83%b3%e3%81%a8%e3%81%ae%e3%82%b3%e3%83%b3%e3%83%95%e3%83%aa%e3%82%af%e3%83%88%e3%81%ae%e8%a7%a3/#post-11674000)
 * 状態: 解決済

## トピック

### 人気のトピック

### 返信がないトピック

### サポート関連ではないトピック

### 解決済みのトピック

### 未解決のトピック

### すべてのトピック
