Home › Forums › Calendar Products › Events Calendar PRO › Calendar Page Title
- This topic has 23 replies, 3 voices, and was last updated 9 years, 10 months ago by
Ben.
-
AuthorPosts
-
June 18, 2016 at 2:15 pm #1128932
Ben
ParticipantI’m trying to track down a problem that has been discussed in several places in the forums, but I haven’t seen a definitive answer. The issue is that when you use the default page template in Event Calendar settings, the page title is set to the title of an event in the calendar, which looks very funky. Since there is no way to place a full calendar on a page that you create yourself (only a mini calendar), the user really has no control over what the page title will be. It seems to me that this is a basic flaw. Either the user should be able to set a page title within the Event Calendar settings (since the plug-in controls the creation of the page), or there should be a way to insert a full calendar on a page created by the user. Can you provide a fix or a viable workaround? In particular, I am working with the CPOThemes Illustrious theme.
June 19, 2016 at 10:49 am #1129029Ben
ParticipantI notice that you have some code in Templates.php and Template_Factory.php to try and deal with this situation (see below). Wouldn’t it be easier to publish an app note for theme developers on how to be compatible with your plug-in? That would help me and other users to get this resolved. Maybe you’ve already done this and I can’t find it. I don’t want to install patches that I have to maintain to make the Event Calendar work properly, so please don’t refer me to those threads. Thanks. –Gene
Template_Factory.php
// implement a filter for the page title. Support WordPress < 4.4
add_filter( 'wp_title', array( $this, 'title_tag' ), 10, 2 );// implement a filter for the page title. Support WordPress >= 4.4
add_filter( 'document_title_parts', array( $this, 'title_tag' ) );// implement a filter for the page title. Support WordPress < 4.4
add_filter( 'wp_title', array( $this, 'title_tag' ), 10, 2 );// implement a filter for the page title. Support WordPress >= 4.4
add_filter( 'document_title_parts', array( $this, 'title_tag' ) );
Templates.php
/**
* Fix issues where themes display the_title() before the main loop starts.
*
* With some themes the title of single events can be displayed twice and, more crucially, it may result in the
* event views such as month view prominently displaying the title of the most recent event post (which may
* not even be included in the view output).
*
* There's no bulletproof solution to this problem, but for affected themes a preventative measure can be turned
* on by adding the following to wp-config.php:
*
* define( 'TRIBE_MODIFY_GLOBAL_TITLE', true );
*
* Note: this reverses the situation in version 3.2, when this behaviour was enabled by default. In response to
* feedback it will now be disabled by default and will need to be turned on by adding the above line.
*
* @see issues #24294, #23260
*/
public static function maybe_modify_global_post_title() {
global $post;// We will only interfere with event queries, where a post is set and this behaviour is enabled
if ( ! tribe_is_event_query() || ! defined( 'TRIBE_MODIFY_GLOBAL_TITLE' ) || ! TRIBE_MODIFY_GLOBAL_TITLE ) {
return;
}
if ( ! isset( $post ) || ! $post instanceof WP_Post ) {
return;
}// Wait until late in the wp_title|document_title_parts hook to actually make a change - this should allow single event titles
// to be used within the title element itself
add_filter( 'document_title_parts', array( __CLASS__, 'modify_global_post_title' ), 1000 );
add_filter( 'wp_title', array( __CLASS__, 'modify_global_post_title' ), 1000 );
}/**
* Actually modifies the global $post object's title property, setting it to an empty string.
*
* This is expected to be called late on during the wp_title action, but does not in fact alter the string
* it is passed.
*
* @see Tribe__Events__Templates::maybe_modify_global_post_title()
*
* @param string $title
*
* @return string
*/
public static function modify_global_post_title( $title = '' ) {
global $post;// Set the title to an empty string (but record the original)
self::$original_post_title = $post->post_title;
$post->post_title = apply_filters( 'tribe_set_global_post_title', '' );// Restore as soon as we're ready to display one of our own views
add_action( 'tribe_pre_get_view', array( __CLASS__, 'restore_global_post_title' ) );// Now return the title unmodified
return $title;
}/**
* Restores the global $post title if it has previously been modified.
*
* @see Tribe__Events__Templates::modify_global_post_title().
*/
public static function restore_global_post_title() {
global $post;
$post->post_title = self::$original_post_title;
remove_action( 'tribe_pre_get_view', array( __CLASS__, 'restore_global_post_title' ) );
}
June 19, 2016 at 10:52 am #1129030Ben
ParticipantP.S. I’m not interested in using the mini-calendar shortcode on a user defined page. The mini-calendar isn’t appropriate for the main calendar on a web site. It would be great if you had a shortcode for the full calendar though. Perhaps another way to address this?
June 19, 2016 at 1:47 pm #1129056Nico
MemberHi Gene,
Thanks for reaching out! Interesting suggestions here, let’s jump into those:
Setting calendar view titles
We have an article describing how to do this: Changing the browser title for calendar views. That should help you out!
Full views shortcodes
This is on our roadmap for upcoming major release 4.3 (August). This is the initial plan and might change in the future, but hopefully we’ll see this feature included in the near future!
There’s a third party plugin for this: The Events Calendar Shortcodes. Personally I haven’t tried it out and of course we cannot support it, but it might help until we have this in our own codebase.
Please let me know if this answers your questions,
Best,
NicoJune 20, 2016 at 10:55 am #1129396Ben
ParticipantI tried this, but it doesn’t work. Could you please help me fix this? Here is my functions.php file in my theme directory:
if(!isset($content_width)) $content_width = 640;
define('CPOTHEME_ID', 'illustriouspro');
define('CPOTHEME_NAME', 'Illustrious Pro');
define('CPOTHEME_VERSION', '1.3.0');
//Other constants
define('CPOTHEME_LOGO_WIDTH', '195');
define('CPOTHEME_USE_SLIDES', true);
define('CPOTHEME_USE_FEATURES', true);
define('CPOTHEME_USE_PORTFOLIO', true);
define('CPOTHEME_THUMBNAIL_WIDTH', '600');
define('CPOTHEME_THUMBNAIL_HEIGHT', '400');//Load Core; check existing core or load development core
$core_path = get_template_directory().'/core/';
if(defined('CPOTHEME_CORE')) $core_path = CPOTHEME_CORE;
require_once $core_path.'init.php';$include_path = get_template_directory().'/includes/';
//Main components
require_once($include_path.'setup.php');// *************PATCH: This filter added to set only the title as a required field (and not description)
add_filter( 'tribe_events_community_required_fields', 'my_community_required_fields', 10, 1 );function my_community_required_fields( $fields ) {
$fields = array(
'post_title'
);
return $fields;
}
//************************************************************************************************************/**
* *************PATCH: Defines page titles for events calendar
*
* @param string $title
* @return string
*/
function filter_events_title_month( $title ) {
if ( tribe_is_month() ) {
$title = 'Events';
}return $title;
}
//*****************************************************************
June 20, 2016 at 11:00 am #1129397Ben
ParticipantP.S. The shortcode you pointed me to does not address my problem. I need to have a viable title on the page that your plug-in generates for all of the views, including the month view.
June 20, 2016 at 3:53 pm #1129568Nico
MemberThanks for following up Gene!
In the code you share you are not including the add_filter part, the complete code for changing month view title should be:
function filter_events_title_month( $title ) {
if ( tribe_is_month() ) {
$title = 'Month view page';
}return $title;
}
add_filter( 'tribe_events_title_tag', 'filter_events_title_month' );
If you are using Yoast SEO or a similar plugin this might not work.
Please let me know about it,
Best,
NicoJune 20, 2016 at 7:24 pm #1129594Ben
ParticipantUpdated functions.php in theme but still doesn’t work. Here is the updated file…looking for same title for all views.
<?php if(!isset($content_width)) $content_width = 640;
define(‘CPOTHEME_ID’, ‘illustriouspro’);
define(‘CPOTHEME_NAME’, ‘Illustrious Pro’);
define(‘CPOTHEME_VERSION’, ‘1.3.0’);
//Other constants
define(‘CPOTHEME_LOGO_WIDTH’, ‘195’);
define(‘CPOTHEME_USE_SLIDES’, true);
define(‘CPOTHEME_USE_FEATURES’, true);
define(‘CPOTHEME_USE_PORTFOLIO’, true);
define(‘CPOTHEME_THUMBNAIL_WIDTH’, ‘600’);
define(‘CPOTHEME_THUMBNAIL_HEIGHT’, ‘400’);//Load Core; check existing core or load development core
$core_path = get_template_directory().’/core/’;
if(defined(‘CPOTHEME_CORE’)) $core_path = CPOTHEME_CORE;
require_once $core_path.’init.php’;$include_path = get_template_directory().’/includes/’;
//Main componentshttps://theeventscalendar.com/
require_once($include_path.’setup.php’);/*
* *************PATCH: Defines page titles for events calendar
*
* @param string $title
* @return string
*/
function filter_events_title( $title ) {
$title = ‘Events’;
return $title;
}
add_filter( ‘tribe_events_title_tag’, ‘filter_events_title’ );June 21, 2016 at 11:04 am #1129989Ben
ParticipantHi Nico, I’m wondering of we are not confusing a couple of issues. Looking back on the source of your recommendation, it appears that Brook was talking about the title that appears above the Events Calendar view. That is apparently what is affected by ‘tribe_events_title_tag’ filter.
What I’m talking about is different, i.e., the PAGE title, as in the title that you would enter for any new page you create in WordPress. It appears that some themes are not able to tell when the page is actually being generated by your plug-in, so it tries to display the page name but is not sure where to get it. Sometimes it ends up getting the title of the current post ID, which looks lame (see attachment).
Can you please provide documentation that will tell me how to determine programmatically within the theme that the page is generated by the events calendar so I can take appropriate action to not generate a page block for the calendar, or create appropriate text for it. Is there an action or filter for this?
Thanks
GeneJune 21, 2016 at 12:24 pm #1130026Ben
ParticipantFor instance, in my Illustrious theme (from CPOThemes), the page title function is the following:
function cpotheme_page_title(){
global $post;
if(isset($post->ID)) $current_id = $post->ID; else $current_id = false;
$title_tag = function_exists(‘is_woocommerce’) && is_woocommerce() && is_singular(‘product’) ? ‘span’ : ‘h1’;
echo ‘<‘.$title_tag.’ class=”pagetitle-title heading”>’;
if(function_exists(‘is_woocommerce’) && is_woocommerce()){
woocommerce_page_title();
}elseif(is_category() || is_tag() || is_tax()){
echo single_tag_title(”, true);
}elseif(is_author()){
the_author();
}elseif(is_date()){
_e(‘Archive’, ‘cpotheme’);
}elseif(is_404()){
echo __(‘Page Not Found’, ‘cpotheme’);
}elseif(is_search()){
echo __(‘Search Results for’, ‘cpotheme’).’ “‘.get_search_query().'”‘;
}else{
echo get_the_title($current_id);
}
echo ‘</’.$title_tag.’>’;
}For the calendar page, the test falls through to the next to last line–echo get_the_title($current_id), so the current event title is displayed. What is needed is a test that recognizes an event post, so the title can be set to “Events”, or the page title block can be disabled for the page.
Can you help me with that?
June 22, 2016 at 2:18 pm #1130585Ben
ParticipantI am having compatibility problems between events calendar and my Illustrious theme from CPOthemes. I need to set a variable that will disable generation of a page title block on the page that holds the calendar, so it will look like a normal blog page.
Can you recommend a tribe hook that occurs just before The Event Calendar calls the theme to generate the page that holds the event calendar (i.e., the page that is generated when http://www.jazzoregon.com?post_type=tribe_events is called from the main menu)?
Can you recommend a filter or variable that will signal to the theme that a calendar page is being generated?
June 23, 2016 at 8:12 am #1130902Nico
MemberThanks for the follow-ups Gene!
Indeed I was confused about the ‘page title’ which for me was the browser title but now I see it’s a title block inserted by the theme. Maybe the best way of dealing with this is to modify the theme function to detect event views as well:
function cpotheme_page_title(){global $post;
if(isset($post->ID)) $current_id = $post->ID; else $current_id = false;
$title_tag = function_exists('is_woocommerce') && is_woocommerce() && is_singular('product') ? 'span' : 'h1';
echo '<'.$title_tag.' class=”pagetitle-title heading”>';if(function_exists('is_woocommerce') && is_woocommerce()){
woocommerce_page_title();
}elseif(is_category() || is_tag() || is_tax()){
echo single_tag_title(”, true);
}elseif(is_author()){
the_author();
}elseif(is_date()){
_e('Archive', 'cpotheme');
}elseif(is_404()){
echo __('Page Not Found', 'cpotheme');
}elseif(is_search()){
echo __('Search Results for', 'cpotheme').' “'.get_search_query().'”';} else if ( function_exists('tribe_is_month') && tribe_is_month() ) {
echo 'Month view page';}else{
echo get_the_title($current_id);
}
echo '</'.$title_tag.'>';
}
Also, please reach out to the theme developers on how to safely store this customization for it to not be overwritten on theme updates,
Best,
NicoJune 23, 2016 at 8:16 am #1130904Nico
MemberGene,
If until we get this going you want to hide the page title for event views use the following CSS snippet:
/* hide theme page title in calendar views */
.post-type-archive-tribe_events #pagetitle {
display: none;
}
Just paste it in your theme (or child theme) stylesheet or via Simple Custom CSS plugin.
Best,
NicoJune 23, 2016 at 10:15 am #1131091Ben
ParticipantThanks, That works great for the calendar views. Is there a similar patch to disable the page title in the single event view? Thanks so much!
June 23, 2016 at 12:47 pm #1131167Nico
MemberSure Gene:
/* hide theme page title in calendar views & single event views */
.post-type-archive-tribe_events #pagetitle,
.single-tribe_events #pagetitle {
display: none;
}
Give it a try and let me know if you are happy with this solution,
Best,
Nico -
AuthorPosts
- The topic ‘Calendar Page Title’ is closed to new replies.
