Skip to content

Instantly share code, notes, and snippets.

@joshfeck
Created August 27, 2014 22:47
Show Gist options
  • Save joshfeck/9f295baf0fdb0ad789cf to your computer and use it in GitHub Desktop.
Save joshfeck/9f295baf0fdb0ad789cf to your computer and use it in GitHub Desktop.
Change the Event page's displayed name using the WP the_title() filter. Requires ee3.5 or greater, but not compatible with EE4.
<?php
/*
Plugin Name: Custom Espresso Event page nice names
Plugin URI: http://gist.github.com/
Description: Changes the page name to be the event name. Requires Event Espresso 3.1.35.P or higher.
Version: 1.0
Author: Josh Feck
License: GPLv2
*/
/**
* Filters the_title() to display the event's name instead of the page's title.
*
*
*/
function ee_event_page_nice_name( $title ) {
// only do stuff if espresso_get_event exists
if ( function_exists('espresso_get_event') ) {
global $this_event_id;
if (isset($this_event_id) && !empty($this_event_id)){
$event_id = $this_event_id;
}
if ( empty( $event_id ) ) return $title ; //get out this isn't an ee page.
$event = espresso_get_event( $event_id );
//one more sanity check
if ( empty( $event ) || !in_the_loop() ) return $title; //get out!
if ( $event_id ) { // if there's an event id...do stuff...
$event = espresso_get_event( $event_id );
$title = '';
// Add the site name.
$title = "$event->event_name";
return $title;
}
}
}
add_action( 'action_hook_espresso_social_display_buttons', 'ee_mod_page_name');
function ee_mod_page_name() {
add_filter( 'the_title', 'ee_event_page_nice_name', 10, 2 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment