Skip to content

Instantly share code, notes, and snippets.

@Pebblo
Forked from joshfeck/venue_mods.php
Last active August 10, 2026 14:14
Show Gist options
  • Select an option

  • Save Pebblo/5431dab560eb246761314e5193bfbf01 to your computer and use it in GitHub Desktop.

Select an option

Save Pebblo/5431dab560eb246761314e5193bfbf01 to your computer and use it in GitHub Desktop.
Move venue address so it appears before venue content. Event Espresso 4
<?php
/**
* By default EE appends the "content-espresso_venues-location.php" template AFTER the
* venue content. It does this via the EED_Venue_Single / EED_Venues_Archive
* ::venue_location() callbacks, which are hooked onto `the_content` (and, for the
* archive, `the_excerpt`) at priority 110 from inside each module's venue_details().
*
* Rather than trying to intercept those filters per-context (the gist approach only
* caught single venues because the archive module re-registers its filters inside the
* loop and also uses `the_excerpt`), we hook the single seam that every venue render
* passes through: the `before_the_content` action fired inside
* content-espresso_venues-details.php, immediately before the_content()/the_excerpt().
*
* There we (1) strip the core "append after content" callbacks so the location isn't
* output twice, then (2) echo the location template ourselves, which lands it just
* before the content in the output buffer for single, archive and category contexts.
*/
add_action(
'AHEE__content_espresso_venues_details_template__before_the_content',
'ee_render_venue_location_before_content',
10,
1
);
/**
* @param WP_Post|null $post the venue post being rendered
* @return void
*/
function ee_render_venue_location_before_content($post)
{
if (! class_exists('EEH_Template')) {
return;
}
// Remove the core callbacks that append the location AFTER the content.
// Only the module handling the current request has actually registered these;
// removing the other is a harmless no-op.
$modules = array();
if (class_exists('EED_Venue_Single')) {
$modules[] = EED_Venue_Single::instance();
}
if (class_exists('EED_Venues_Archive')) {
$modules[] = EED_Venues_Archive::instance();
}
foreach ($modules as $module) {
remove_filter('the_content', array($module, 'venue_location'), 110);
remove_filter('the_excerpt', array($module, 'venue_location'), 110);
}
// Output the location block now, i.e. before the content is rendered.
// The template reads the global $post, which is the current venue here.
echo EEH_Template::locate_template('content-espresso_venues-location.php');
}
<?php
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file
add_action('pre_get_posts', 'my_change_venue_details');
function my_change_venue_details() {
global $post;
if ($post instanceof WP_Post && $post->post_type == 'espresso_venues' && is_single()) {
remove_filter('the_content', array(EED_Venue_Single::instance(), 'venue_location'), 110, 1);
add_filter('the_content', 'add_venue_details_in_custom_order', 120, 1);
}
}
function add_venue_details_in_custom_order($content) {
$content = EEH_Template::locate_template('content-espresso_venues-location.php')
. '<br>'
. $content;
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment