Changing String of Text in Post Content

Home Forums Calendar Products Events Calendar PRO Changing String of Text in Post Content

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #1351453
    Steven Frasier
    Participant

    My company recently went through a name change—from New York Society of Security Analysts (NYSSA) to CFA Society New York (CFANY)—and I was hoping to easily change all pertinent references within event-post content accordingly.

    I had no luck with the below oft-referenced snippet found here:

    <?php
     
    /*
     * EXAMPLE OF CHANGING ANY TEXT (STRING) IN THE EVENTS CALENDAR
     * See the codex to learn more about WP text domains:
     * http://codex.wordpress.org/Translating_WordPress#Localization_Technology
     * Example Tribe domains: 'tribe-events-calendar', 'tribe-events-calendar-pro'...
     */
    function tribe_custom_theme_text ( $translation, $text, $domain ) {
     
    	// Put your custom text here in a key => value pair
    	// Example: 'Text you want to change' => 'This is what it will be changed to'
    	// The text you want to change is the key, and it is case-sensitive
    	// The text you want to change it to is the value
    	// You can freely add or remove key => values, but make sure to separate them with a comma
    	// This example changes the label "Venue" to "Location", and "Related Events" to "Similar Events"
    	$custom_text = array(
    		'Venue' => 'Location',
    		'Related %s' => 'Similar %s',
    	);
     
    	// If this text domain starts with "tribe-", "the-events-", or "event-" and we have replacement text
        	if( (strpos($domain, 'tribe-') === 0 || strpos($domain, 'the-events-') === 0 || strpos($domain, 'event-') === 0) && array_key_exists($translation, $custom_text) ) {
    		$translation = $custom_text[$translation];
    	}
        return $translation;
    }
    add_filter('gettext', 'tribe_custom_theme_text', 20, 3);

    I plugged in the following:

    /*
     * EXAMPLE OF CHANGING ANY TEXT (STRING) IN THE EVENTS CALENDAR
     * See the codex to learn more about WP text domains:
     * http://codex.wordpress.org/Translating_WordPress#Localization_Technology
     * Example Tribe domains: 'tribe-events-calendar', 'tribe-events-calendar-pro'...
     */
    function tribe_custom_theme_text ( $translation, $text, $domain ) {
    $custom_text = array(
    'New York Society of Security Analysts' => 'CFA Society New York',
    'NYSSA' => 'CFANY',
    );
    if( (strpos($domain, 'tribe-') === 0 || strpos($domain, 'the-events-') === 0 || strpos($domain, 'event-') === 0) && array_key_exists($translation, $custom_text) ) {
    $translation = $custom_text[$translation];
    }
    return $translation;
    }
    add_filter('gettext', 'tribe_custom_theme_text', 20, 3);

    I have cleared my cache and waited plenty of time, but see no change. For what it’s worth, I was wondering whether this was simply because I was attempting to accomplish the task on my dev site (dev.cfany.org), but the function worked for (meta?) labels, just not for text within the content of the single event page as I intended.

    • This topic was modified 8 years, 7 months ago by Steven Frasier. Reason: Corrected the display of first code snippet
    #1352109
    Patricia
    Member

    Hey Jared,

    Thank you for reaching out to us!

    I would suggest you a different (perhaps easier) approach to achieve what you want:

    Run a complete database search-replace via WP_CLI or export your DB and search-replace this file using a command like sed.

    If you want us to help you with this task, please export your database and share the .sql file with us via Google Drive or Drop Box in a private reply.

    Also, please confirm that the strings you want to change are:

    1- From “New York Society of Security Analysts” to “CFA Society New York” and
    2- From “(NYSSA)” to “(CFANY)”.

    I hope this helps! Let me know if you have any other questions or need further assistance in the mean time!

    Best Regards,

    Patricia

    #1352126
    Steven Frasier
    Participant

    Sincerely appreciate the thorough response, Patricia.

    My primary concern with running this across the “complete” database is that some references, like in a recent press release for example, intentionally reference our old name. These instances are few and far between, so perhaps I could just address those examples manually following the change.

    Would this serve to replace all references moving forward automatically? Or would it simply make the changes to current database content only? The latter option is preferred in case we would like to reference our former name for whatever reason.

    I suppose the other option, if possible, would be to limit the changes strictly to tribe-events posts, but I think I’d actually prefer to make the changes site-wide as you suggested (assuming this doesn’t automate the change for all future references), and correct references individually as need be.

    All of that said, the strings are the following:

    1. From “New York Society of Security Analysts” to “CFA Society New York”
    2. From “NYSSA” to “CFANY” — no need for the parenthesis

    I would in fact appreciate your help with the process either way. How do you recommend I go about exporting the database as a .sql file?

    Thanks so much!

    #1352516
    Patricia
    Member

    Hi Jared!

    Answering your questions: it would modify only the current database content: the database search-replace is a one time process that take a few seconds to complete (it could take more time depending on the size of your database). And yes, this change will affect your entire database, not only tribe-events posts.

    The most common way to access your database is by using a tool called phpMyAdmin, so I would suggest you to follow the steps mentioned in this article to export it.

    If you are having problems to export your database, I would suggest you to contact your hosting provier to help you with this task!

    Once you export your database, please send me the Google Drive or Dropbox link via private reply so I can run the search-replace for you.

    Thanks!

    Patricia

    #1352625
    Steven Frasier
    Participant

    This reply is private.

    #1353135
    Patricia
    Member

    This reply is private.

    #1353433
    Steven Frasier
    Participant

    This reply is private.

    #1353584
    Patricia
    Member

    This reply is private.

    #1353599
    Steven Frasier
    Participant

    This reply is private.

    #1353655
    Patricia
    Member

    This reply is private.

    #1363736
    Support Droid
    Keymaster

    Hey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.

    Thanks so much!
    The Events Calendar Support Team

Viewing 11 posts - 1 through 11 (of 11 total)
  • The topic ‘Changing String of Text in Post Content’ is closed to new replies.