実現したいこと
xo_event_calendarプラグインを使ってイベントのタイトルをカレンダー下へ表示したい
前提
xamppを使い、ローカル環境でWordPress(ver.6.2)をインストールしています。
xo_event_calendarプラグイン(ver.3.1.2)をインストールしています。
プラグインを入れると、『イベント』というカスタム投稿タイプが生成されます。
カスタム投稿タイプ『イベント』に入力したタイトルをカレンダーの下へ表示するために参考サイトと同様に
functions.phpへコードを追記しました。
https://xakuro.com/wordpress/xo-event-calendar/xo-event-calendar-month/
参考サイトのコード
functions.php
1function my_event_calendar_month( $html, $args, $month_index, $events ) { 2 if ( $events ) { 3 $footer = '<div class="events-list">'; 4 foreach ( $events as $event ) { 5 $post = $event['post']; 6 $footer .= '<p>' . esc_html( $post->post_title ) . '</p>'; 7 } 8 $footer .= '</div>'; 9 $html .= $footer; 10 } 11 return $html; 12} 13add_action( 'xo_event_calendar_month', 'my_event_calendar_month', 10, 4 );
カレンダーを表示するためのコード
page.php
1<?php echo do_shortcode( '[xo_event_calendar holidays="all" months="2" next="6" previous="6"]' ); ?>
掃き出されたHTMLの概略
HTML
1<div id="xo-event-calendar-1" class="xo-event-calendar"> 2 <div class="calendars xo-months"> 3 <div class="calendar xo-month-wrap"> 4 ~カレンダーの中身~ 5 </div> 6 <div class="events-list"><p>○○○特別展</p></div> 7 <div class="calendar xo-month-wrap"> 8 ~カレンダーの中身~ 9 </div> 10 <div class="events-list"><p>○○○特別展</p></div> 11 </div> 12 13 <div class="holiday-titles"><p class="holiday-title"><span style="background-color: #fddde6;"></span>定休日</p></div> 14 <div class="loading-animation"></div> 15</div> 16
発生している問題・エラーメッセージ

試したこと
文字の置き換えを試しましたが、表示されませんでした。
functions.php
1function my_event_calendar_month( $html, $args, $month_index, $events ) { 2 if ( $events ) { 3 $footer = '<div class="events-list">'; 4 foreach ( $events as $event ) { 5 $post = $event['post']; 6 $footer .= '<p>' . esc_html( $post->post_title ) . '</p>'; 7 } 8 $footer .= '</div>'; 9 // holiday-titlesの後、つまりcalendar-loading-animationの手前 10 $html = str_replace( '<div class="calendar-loading-animation"></div>', $footer . '<div class="calendar-loading-animation"></div>', $html ); 11 } 12 return $html; 13} 14add_action( 'xo_event_calendar_month', 'my_event_calendar_month', 10, 4 ); 15
行き詰っており、何か良いヒントを教えていただければ幸いです。

0 コメント