Home › Forums › Calendar Products › Events Calendar PRO › Page Title Issues
- This topic has 9 replies, 2 voices, and was last updated 10 years, 3 months ago by
Brook.
-
AuthorPosts
-
January 12, 2016 at 6:40 pm #1054925
Sean
ParticipantHi. I’ve noticed a few quirks with the calendar’s default page titles. They don’t effect functionality, but for SEO purposes, they are a problem.
On List view, the page title is: “Upcoming Events | Events | Site Name”
On Day view, the page title is: “Events for January 12, 2016 | Events | Site Name”
On Map view, the page title is: “Events for January 12 – January 21 | Events | Site Name”
On Single Event pages, the page title is: “Upcoming Events | Single Event Title | Site Name”Using this snippet I’ve been able to modify the page titles for Single Events to be “Single Event Title | Site Name”. However, the List, Day and Map views are still displaying the extra “| Events” in the title. In my case, the title of List and Map Views have been set to “Upcoming Events” and Day View should be “Events for DAY HERE”.
Since your demo (wpshindig.com) also displays the same default page titles, I’m guessing you may already be aware of this to some degree…but in any case, is this a bug or does that snippet need to be updated for version 4.0?
January 12, 2016 at 11:58 pm #1054998Brook
ParticipantHowdy again Karly,
Map and Photo views are list views on the backend. So using that snippet whatever you input for the the list views will show up on all three views: Map, Photo, and List. You could definitely modify the snippet to account for the different types of list views though, using the functions tribe_is_photo() and tribe_is_map() you could account for more views than default. Then display different bits of text. The block of code which handles list views, upcoming and otherwise is the first one:
// Default Title $title = $title_upcoming; // If there's a date selected in the tribe bar, show the date range of the currently showing events if ( isset( $_REQUEST['tribe-bar-date'] ) && $wp_query->have_posts() ) { if ( $wp_query->get( 'paged' ) > 1 ) { // if we're on page 1, show the selected tribe-bar-date as the first date in the range $first_event_date = tribe_get_start_date( $wp_query->posts[0], false ); } else { //otherwise show the start date of the first event in the results $first_event_date = tribe_event_format_date( $_REQUEST['tribe-bar-date'], false ); } $last_event_date = tribe_get_end_date( $wp_query->posts[ count( $wp_query->posts ) - 1 ], false ); $title = sprintf( $title_range, $first_event_date, $last_event_date ); } elseif ( tribe_is_past() ) { $title = $title_past; }Does that answer your question?
Cheers!
– Brook
January 13, 2016 at 12:37 pm #1055532Sean
ParticipantThis reply is private.
January 13, 2016 at 10:15 pm #1055754Brook
ParticipantOhh, so you are trying to modify <title> tag not the page titles/headers. For that we have an entirely different snippet: http://pastebin.com/QU2aMwBJ It even has some special tips if you are running Yoast. You will still see the sitename at the end, but unless Yoast is overriding it the | Events | portion should be gone. That snippet do what you want?
Cheers!
– Brook
January 14, 2016 at 1:37 pm #1056202Sean
ParticipantAh, okay I see the difference now (title tag vs page titles). Sorry about that – this is a bit of a new area for me 🙂
This snippet definitely helps change some of the tags. After some testing I found that although I have Yoast running, the tribe_events_title_tag filter combined with this snippet allows me to edit the title tags for all of the main views (the Single Event, Single Venue and Single Organizer pages don’t change, but they are fine as is). Removing the Month View from the filter_events_title function also allows the Month View to continue showing as is, which is “Events for January 2016 | My Site Name”, which is also fine as is. Hopefully this will help anyone else that is running Yoast and finds that the using only one of these two snippets doesn’t work for them either…
With that said, the one View that is still not ideal is Day View. When only the “Prevent Yoast from changing Event Title Tags” function activated, that tag is Events for January 12, 2016 | Events | My Site Name, while if I add Day View to the tribe_events_title_tag filter, it only shows the custom title.
Is there a way to set the Day View’s custom title tag to dynamically be the date selected (as is the case above for the Month View)? For example, if today was selected, the tag would be Events for Thursday, January 14, 2016 | My Site Name. I tried copying the Day view’s page title – Events for %1$s – to the custom title tag, but the %1$s isn’t being replaced with the relevant date. If not we can deal with the extra “| Events” still being there in the title, but if there is a way to pull in the date to the custom tag, that’d be great!
January 14, 2016 at 8:27 pm #1056325Brook
ParticipantNo worries, the words title and header are pretty interchangeable here. It confuses us all at times.
That can definitely happen with Day View as well. The magic that powers Day View’s header, and replaces the %1$s, is the sprintf() function:
$title = sprintf( 'Events for %1$s', date_i18n( tribe_get_date_format( true ), strtotime( $wp_query->get( 'start_date' ) ) ) );I believe setting dayview to that $title variable will do what you want. 🙂 Does it?
- Brook
January 15, 2016 at 4:20 am #1056396Sean
ParticipantHey Brook,
So I gave that a try but it’s throwing a fatal error:
Notice: Undefined variable: wp_query in /wp-content/themes/mytheme/functions.php on line 430 Fatal error: Call to a member function get() on a non-object in /wp-content/themes/mytheme/functions.php on line 430I understand this is a bit out of typical scope of support here, but if there’s any way you can share a fix for that it would be a big help in getting that last tag tackled.
Thanks again for everything,
KarlyJanuary 18, 2016 at 9:16 am #1057937Brook
ParticipantOh I did not think about that. Find this line:
function filter_events_title ($title) {And add this underneath it:
global $wp_query;If anything can fix this that can. However, it might just change the error message you get, or it might show an erroneous date in the <title>. This is because $wp_query has not been fully setup at the point the <title> is output. In order to work around this it will get ridiculously complicated. 🙁 It will require a very advanced knowledge of PHP to either setup the date, or to use ob_start() to capture the output of the page and try loading the <title> date afterthe page but outputting it first.
Let me know how it goes. Hopefully the simple fix I detailed at the outset is all we need!
You’re very welcome. We really value your contributions in helping us find bugs.
- Brook
January 18, 2016 at 1:30 pm #1058086Sean
ParticipantGreat news, adding global $wp_query; is all that was needed! Thanks again Brook for helping me get to the finish line with this!
Best,
KarlyJanuary 18, 2016 at 9:23 pm #1058291Brook
ParticipantHappiness! That’s what we wanted to hear.
’til next time!
- Brook
-
AuthorPosts
- The topic ‘Page Title Issues’ is closed to new replies.
