Last active
December 30, 2015 12:49
-
-
Save joshfeck/7832044 to your computer and use it in GitHub Desktop.
This is a little plugin that adds the event name to the page's <title> tag. Requires Event Espresso 3.1.35.P or higher.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Custom Espresso Title tags | |
Plugin URI: http://gist.github.com/ | |
Description: Adds the event name to the page's <title> tag. Requires Event Espresso 3.1.35.P or higher. | |
Version: 1.0 | |
Author: Josh Feck | |
License: GPLv2 | |
*/ | |
/** | |
* Creates a nicely formatted and more specific title element text | |
* for output in head of document, based on current event. | |
* | |
*/ | |
function ee_reg_page_title( $title, $sep ) { | |
// 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 ) ) return $title; //get out we don't have an event. | |
if ( $event_id ) { // if there's an event id...do stuff... | |
$event = espresso_get_event( $event_id ); | |
$title = ''; | |
// Add the site name. | |
$title .= get_bloginfo( 'name' ); | |
// Add the event name. | |
$title = "$event->event_name $sep $title"; | |
return $title; | |
} | |
} | |
} | |
add_action( 'action_hook_espresso_social_display_buttons', 'ee_mod_page_title'); | |
function ee_mod_page_title() { | |
add_filter( 'wp_title', 'ee_reg_page_title', 10, 2 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment