我正在使用The Events Calendar 处理我正在创建的站点上的事件。
如果用户位于事件页面(归档、单张等),我希望启用include。我的include有一些自定义挂钩,用于处理入队、出队和插入自定义HTML。
以下是我测试的内容:
/**
* Detect Tribe Events and add text to top of page
*/
if ( class_exists( \'Tribe__Events__Main\' ) ) { // Only triggers if plugin is active
function is_tribe_calendar() {
if (tribe_is_event() || tribe_is_event_category() || tribe_is_in_main_loop() || tribe_is_view() || \'tribe_events\' == get_post_type() || is_singular( \'tribe_events\' ))
echo \'<p style="background: red; color: white; padding: 24px; margin: 0;">Tribe Events is active.</p>\';
}
add_action( \'wp_head\' , \'is_tribe_calendar\' );
}
如果用户正在存档(日历)或单个事件中,此功能可以完美地工作,并将文本添加到页面顶部。根据我的测试,我写了以下内容:
/**
* Detect Trive Events and require include
*/
if ( class_exists( \'Tribe__Events__Main\' ) ) { // Only triggers if plugin is active
function is_tribe_calendar() {
if (tribe_is_event() || tribe_is_event_category() || tribe_is_in_main_loop() || tribe_is_view() || \'tribe_events\' == get_post_type() || is_singular( \'tribe_events\' ))
require get_template_directory() . \'/inc/tribe-events.php\';
}
add_action( \'wp_head\' , \'is_tribe_calendar\' );
}
我不认为wp_head
是这里合适的钩子,因为我想用一些自定义PHP加载一个include。我是否应该为这种功能使用挂钩?