Support

Home Forums Events Calendar Add-on Change text of "Category legend"

Change text of "Category legend"

Posted: February 5, 2016 at 1:08 pm

Viewing 4 reply threads


Bethany Care Society

February 5, 2016 at 1:08 pm

Hi,

My client wants to change the text of category legend “Click to select a category” on the calendar to “Click to sort by site”.

What code shall I change or add to my child theme to change this text and also make it bigger by 2 to 3 points?

I can’t really show you the website it appears on as it’s a protected intranet.

All EE4 plugins are up to date.

Thank you,


Josh

  • Support Staff

February 5, 2016 at 2:07 pm

Hi Aurelien,

You’d add the code to change this into your child theme. First, to change the text string, you add a translation function to your child theme’s functions.php file. A translation function can be used to change one or many strings. The string that you’re changing is Click to select a category:. Here’s a link to the documentation that shows and example of a translation function:

https://eventespresso.com/wiki/how-to-change-wording-with-poedit/#custom-function

Then, you add some CSS to your child theme’s style.css file. The selectors you’re going to target are #espresso-category-legend p.

So for example, something like this will change the font-size:

#espresso-category-legend p{
font-size: 1.3em;
}


Bethany Care Society

February 5, 2016 at 5:24 pm

Hi Josh,

Thank you for you reply.

Here’s what I have for php but it doesn’t work:
———————————————–
function mycustom_filter_gettext( $translated, $original, $domain ) {

// This is an array of original strings
// and what they should be replaced with
$strings = array(
‘Click to select a category’ => ‘Click to sort by site’,
// Add some more strings here
);

// See if the current string is in the $strings array
// If so, replace its translation
if ( isset( $strings[$original] ) ) {
// This accomplishes the same thing as __()
// but without running it through the filter again
$translations = get_translations_for_domain( $domain );
$translated = $translations->translate( $strings[$original] );
}

return $translated;
}

add_filter( ‘gettext’, ‘mycustom_filter_gettext’, 10, 3 );
———————————————–

The CSS works though.

What am I not doing properly with the php for it not to work?

Also, your code states it’s for EE3 only whereas I have EE4 installed, does that matter?

I’ve added this code to the functions.php of my child theme.

Thank you,


Tony

  • Support Staff

February 8, 2016 at 2:52 am

Hi there,

The EE3 only reference is in relation to the custom files add-on (as that is only available for EE3), not the code on that page.

When translating strings you need to match the original string exactly, you’ll notice in Josh’s reply he has:

Click to select a category:

In your code above you have:

Click to select a category
(Missing the colon from the end)

So you can’t something like this:

'Click to select a category:' => 'Click to sort by site:',

The above code should then work fine.


Bethany Care Society

February 8, 2016 at 9:24 am

Thanks Tony, it now works correctly.

Thanks a lot for your help!

Viewing 4 reply threads

The support post ‘Change text of "Category legend"’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso