Unable to remove ‘Events for’ from the month title.

Home Forums Calendar Products Community Events Unable to remove ‘Events for’ from the month title.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1098014
    Kurt
    Participant

    I am simply trying to remove the ‘Events for’ from the month title but cannot find it anywhere in the plugin. My desired goal is to just have the current month and year as the title, and have it change depending on what month the user is on. I have searched the document multiple times for the string, checked the database, and looked at the tribe_events_title() function.

    #1098590
    Barry
    Member

    Hi Kurt,

    A small snippet like this one may help:

    function strip_events_for_from_titles( $title ) {
    	return str_replace( 'Events for', '', $title );
    }
    
    add_filter( 'tribe_get_events_title', 'strip_events_for_from_titles' );

    This could go in a custom plugin file or just in your theme’s functions.php file if that’s an approach you prefer.

    Does that help?

    #1098645
    Kurt
    Participant

    Hey Barry,

    Thanks for the reply. I tried implementing that and it completely removes the string (kind of wild). Yesterday I tried something similar to that:

    $subject = tribe_events_title();
    $search = ‘Events for’;
    $trimmed = str_replace($search, ”, $subject);

    and got the same issue where the string is completely removed.

    #1098649
    Barry
    Member

    Hi Kurt,

    Very odd!

    It certainly works for me locally, so I’m not too sure why it fails in your case specifically. Can you post a link to your site in case that sheds some light on the situation?

    I can’t make any promises, but I’d be happy to take a further look 🙂

    #1098677
    Kurt
    Participant

    Hi Barry,

    So I guess I didn’t have PHP errors on my local build, but when I pushed up to the staging url I am seeing quite a few errors that could be the reason why it is not working.

    #1098747
    Barry
    Member

    Thanks Kurt!

    So for some reason it is unable to find the strip_events_for_from_titles() function … can you tell me where exactly you added the above snippet? Can you copy and paste the entire file and share it (ideally, using Gist, Pastebin, Dropbox or some similar service rather than by pasting it directly into the forum)?

    Thanks!

    #1098938
    Kurt
    Participant

    Hey Barry,

    I pasted that into the functions.php, here is the copy pastebin containing strip_events_for_from_title();

    • This reply was modified 10 years ago by Kurt.
    #1098949
    Barry
    Member

    Hi Kurt,

    Thanks for sharing that!

    So in the case of this particular theme, if you include that code in the functions.php file you will need to amend the add_filter() code to read:

    add_filter( 'tribe_get_events_title', __NAMESPACE__ . '\strip_events_for_from_titles' );

    Or, you could alternatively re-work the snippet to use an anonymous function like so:

    add_filter( 'tribe_get_events_title', function( $title ) {
    	return str_replace( 'Events for', '', $title );
    } );
    #1098952
    Kurt
    Participant

    Thanks Barry!

    That worked and I appreciate all of your help!

    #1098957
    Barry
    Member

    My pleasure 🙂

Viewing 10 posts - 1 through 10 (of 10 total)
  • The topic ‘Unable to remove ‘Events for’ from the month title.’ is closed to new replies.