← Back
Editing: acf-excerpt.php
<?php function dmm_append_acf_to_excerpt($excerpt) { // Only modify excerpt on home or archive pages if (is_home() || is_archive()) { // Get ACF fields with fallbacks $time = sanitize_text_field(get_field('course_time') ?: get_field('a_time') ?: ''); $date = sanitize_text_field(get_field('course_date') ?: get_field('a_date') ?: ''); $location = sanitize_text_field(get_field('course_location') ?: get_field('a_location') ?: ''); $participants = sanitize_text_field(get_field('course_participants') ?: ''); $price = sanitize_text_field(get_field('course_price') ?: ''); $link = esc_url(get_field('course_link') ?: ''); $member = get_field('a_member_only') ?: get_field('course_member_only') ?: false; $external_link = get_field('course_external_link') ?: false; $custom_content = ''; // Add member-only notice if applicable if ($member) { $excerpt .= '<div class="member" style="display:none">Kun medlemmer</div>'; } if ($external_link) { $excerpt .= '<div class="course-external-link" style="display:none"></div>'; } // Build course details list if (!empty($time)) { $custom_content .= sprintf('<li class="course-time"><span class="time">%s</span></li>', esc_html($time)); } if (!empty($date)) { $custom_content .= sprintf('<li class="course-date"><label>Dato:</label> <span class="date">%s</span></li>', esc_html($date)); } if (!empty($location)) { $custom_content .= sprintf('<li class="course-location"><span class="location">%s</span></li>', esc_html($location)); } if (!empty($participants)) { $custom_content .= sprintf('<li class="course-participant"><span class="participant">%s</span> <label>deltagere</label></li>', esc_html($participants)); } // Append list if there's content if (!empty($custom_content)) { $excerpt .= '<div><ul class="course-details">' . $custom_content . '</ul>'; } else { $excerpt .= '<div>'; } // Add price if available if (!empty($price)) { $excerpt .= sprintf('<p class="course-price"><label>Pris:</label><span class="price">%s</span></p>', esc_html($price)); } // Add link button if available if (!empty($link)) { $excerpt .= sprintf('<div class="course-button"><a href="%s" class="course-link register" target="_blank" rel="noopener noreferrer">Læs mere</a></div></div>', esc_url($link)); } } //if ( is_singular( 'kursus' ) ) { // $external_link = get_field('hide_registration_link') ?: false; //} return $excerpt; } add_filter('get_the_excerpt', 'dmm_append_acf_to_excerpt', 10, 1);
Save File
Cancel