Skip to content

Instantly share code, notes, and snippets.

@joshfeck
Last active December 30, 2015 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshfeck/7832044 to your computer and use it in GitHub Desktop.
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.
<?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