重要なお知らせ

「教えて! goo」は2025年9月17日(水)をもちまして、サービスを終了いたします。詳細はこちら>

電子書籍の厳選無料作品が豊富!

お忙しい中恐れ入ります。
WordPressにてPHP8.2にて使用しているのですが、どうしても上記Warning・・・・。が消せません。

何かの未定義なのでしょうけれど、一つ直すと違う行が同じWarning・・・・。と表示されてしまいます。


コードは以下になります。


---------------------------------------------------------------------------------------------------------

//内部リンクをはてなカード風にするショートコード
function nlink_scode($atts) {
extract(shortcode_atts(array(
'url'=>"",
'title'=>"",
'excerpt'=>""
),$atts));

$id = url_to_postid($url);//URLから投稿IDを取得
$post = get_post($id);//IDから投稿情報の取得
$date = mysql2date('Y-m-d H:i', $post->post_date);//投稿日の取得

$img_width ="200";//画像サイズの幅指定
$img_height = "200";//画像サイズの高さ指定
$no_image = get_template_directory_uri().'/images/no-img.png';//アイキャッチ画像がない場合の画像を指定

//抜粋を取得
if(empty($excerpt)){
if($post->post_excerpt){
$excerpt = get_the_custom_excerpt($post->post_excerpt , 90);

}else{
$excerpt = get_the_custom_excerpt($post->post_content , 90);
}
}





//タイトルを取得
if(empty($title)){
$title = esc_html(get_the_title($id));
}


//アイキャッチ画像を取得
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 .='<div>
<a href="'. $url .'" class="tmt-blog-card">
<div class="tmt-blog-card-box">
<div class="tmt-blog-card-thumbnail loading=”lazy”">'. $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="clear"></div>
</a></div>';

return $nlink;
}

add_shortcode("nlink", "nlink_scode");
---------------------------------------------------------------------------------------------------------

上記の89行目は、以下の部分になるのですが、

<div class="tmt-blog-card-excerpt">'. $excerpt .'</div>◯◯◯
                            ↑
上記の◯◯の部分にはsvgを記載しています。質問の長さが入り切らなかったので省略しました。

svgの有無に関わらず、
上記コードにて未定義のものがあるのでしょうか?

svgがいけないのでしょうか?
それともやはり何か未定義のものがあるのでしょうか?


お忙しい中大変恐れ入りますが、
何卒ご教授お願い申し上げます。


お願い申し上げます。

なお、
PHP8のエラー回避の以下コードを使用して一応はError表示を非表示にはしているのですが、
将来的なことも考えて、
上記コードのどこがいけないのかご教授いただけましたら幸いです。

よろしくお願い申し上げます。

  • 画像を添付する (ファイルサイズ:10MB以内、ファイル形式:JPG/GIF/PNG)
  • 今の自分の気分スタンプを選ぼう!
あと4000文字

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!