{"id":1896507,"date":"2019-10-18T13:19:18","date_gmt":"2019-10-18T17:19:18","guid":{"rendered":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/change-the-wording-of-any-bit-of-text-or-string-2\/"},"modified":"2022-03-14T15:05:11","modified_gmt":"2022-03-14T19:05:11","slug":"change-the-wording-of-any-bit-of-text-or-string","status":"publish","type":"post","link":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/change-the-wording-of-any-bit-of-text-or-string\/","title":{"rendered":"Custom Wording in the Calendar"},"content":{"rendered":"\n<p>The featured&nbsp;snippet here will help you change any piece of text in The Events Calendar and its add-ons. With a little bit of modification, it would even allow you to change the wording of any piece of text anywhere in WordPress, not just this plugin!<\/p>\n\n\n\n<p>First copy\/paste <a href=\"#snippet\">the snippet at the bottom of this page<\/a> to your theme&#8217;s functions.php. You may need to remove the opening <strong>&lt;?php<\/strong> tag if your theme&#8217;s functions.php already has one.<\/p>\n\n\n\n<p>This snippet already contains two wording changes, which you can use as a template for the changes you want to make. This changes the phrase &#8220;Related Events&#8221; to &#8220;Similar Events&#8221; and &#8220;Venue&#8221; to &#8220;Location.&#8221; This is the magic bit right here:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n$custom_text = &#x5B;\n  &#039;Venue&#039; =&gt; &#039;Location&#039;,\n  &#039;Related %s&#039; =&gt; &#039;Similar %s&#039;,\n];\n<\/pre><\/div>\n\n\n<p>To change a particular set of text, you must first copy it exactly as it appears in the <em>code<\/em>. Frequently it appears the same on the front-end. For instance, to change the wording of &#8220;Related Events&#8221; to say &#8220;Similar Events&#8221;, you can simply copy the text from the front end. You will then paste it as a key inside of the $custom_text array inside of the snippet as in the above example. You can add as many lines as you want by following the same pattern.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/images.theeventscalendar.com\/kb\/uploads\/2014\/09\/KB-example-Similar-Events-665x282.png\" alt=\"KB example Similar Events\"\/><\/figure>\n\n\n\n<p>Sometimes the text you want to change cannot be copy-pasted from the front end. For instance, by default, the label in the <a href=\"https:\/\/staging.theeventscalendar.com\/knowledgebase\/k\/understanding-and-customizing-the-tribe-events-bar\/\">Events Bar<\/a>&nbsp;has&nbsp;a CSS&nbsp;style that transforms &lt;label&gt;s to all caps. If we copy-pasted&nbsp;&#8220;SEARCH&#8221; or &#8220;WEEK OF&#8221; they will not replace the text we want, because&nbsp;that is not how they appear in the code. If we inspect these elements we will see something like this:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n&lt;label&gt;Search&lt;\/label&gt;\n<\/pre><\/div>\n\n\n<p>In order to change&nbsp;that label, we would have to copy it as it appears in the <em>code<\/em>, namely &#8220;Search&#8221;, not &#8220;SEARCH&#8221;. An example which changes &#8220;Search&#8221; to &#8220;Find&#8221;:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n$custom_text = &#x5B;\n  &#039;Related %s&#039; =&gt; &#039;Similar %s&#039;,\n  &#039;Search&#039; =&gt; &#039;Find&#039;, \n];\n<\/pre><\/div>\n\n\n<p>In the above examples, you may have been wondering what the <code>%s<\/code> is all about. Those are placeholders for words that the translation does not change. So `Related %s` allows you to change the word &#8220;Events&#8221; (in the settings), but is not responsible for translating it &#8211; it only translates the word &#8220;Related&#8221;.<\/p>\n\n\n\n<p class=\"has-background\" style=\"background-color:var(--global-palette8)\">\u26a0\ufe0f Note: On rare occasions, this can be even more complicated when multiple strings are concatenated together. An example would be a heading like &#8220;Events for the week of November 24, 2014.&#8221; When attempting to edit these it might become necessary to dive into the PHP code and determine how the individual strings appear in the code, and what their <code>gettext<\/code> <code>$text value<\/code> is.<\/p>\n\n\n\n<p>To help get more accurate translations, WordPress provides translations with context and translations for singular\/plural. These use slightly different filters to account for the extra information, and may not get caught by the <code>gettext<\/code> filter. Since we use these in some places, we have included examples addressing these in the code below as well.<\/p>\n\n\n\n<p id=\"snippet\">And here is the full snippet:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n&lt;?php\n\n\/*\n * EXAMPLE OF CHANGING ANY TEXT (STRING) IN THE EVENTS CALENDAR\n * See the codex to learn more about WP text domains:\n * http:\/\/codex.wordpress.org\/Translating_WordPress#Localization_Technology\n * Example Tribe domains: &#039;tribe-events-calendar&#039;, &#039;tribe-events-calendar-pro&#039;...\n *\/\n\n\/**\n * Put your custom text here in a key =&gt; value pair\n * Example: &#039;Text you want to change&#039; =&gt; &#039;This is what it will be changed to&#039;.\n * The text you want to change is the key, and it is case-sensitive.\n * The text you want to change it to is the value.\n * You can freely add or remove key =&gt; values, but make sure to separate them with a comma.\n * This example changes the label &quot;Venue&quot; to &quot;Location&quot;, &quot;Related Events&quot; to &quot;Similar Events&quot;, and &quot;(Now or date) onwards&quot; to &quot;Calendar - you can discard the dynamic portion of the text as well if desired.\n*\/\nfunction tribe_replace_strings() {\n\t$custom_text = &#x5B;\n\t\t&#039;Venue&#039; =&gt; &#039;Location&#039;,\n\t\t&#039;Related %s&#039; =&gt; &#039;Similar %s&#039;,\n\t\t&#039;%s onwards&#039; =&gt; &#039;Calendar&#039;,\n\t];\n\n\treturn $custom_text;\n}\n\n\n\nfunction tribe_custom_theme_text ( $translation, $text, $domain ) {\n\t\/\/ If this text domain doesn&#039;t start with &quot;tribe-&quot;, &quot;the-events-&quot;, or &quot;event-&quot; bail.\n\tif ( ! check_if_tec_domains( $domain ) ) {\n\t\treturn $translation;\n\t}\n\n\t\/\/ String replacement.\n\t$custom_text = tribe_replace_strings();\n\n\t\/\/ If we don&#039;t have replacement text in our array, return the original (translated) text.\n\tif ( empty( $custom_text&#x5B;$translation] ) ) {\n\t\treturn $translation;\n\t}\n\n\treturn $custom_text&#x5B;$translation];\n}\n\n\n\nfunction tribe_custom_theme_text_plurals ( $translation, $single, $plural, $number, $domain ) {\n\t\/\/ If this text domain doesn&#039;t start with &quot;tribe-&quot;, &quot;the-events-&quot;, or &quot;event-&quot; bail.\n\tif ( ! check_if_tec_domains( $domain ) ) {\n\t\treturn $translation;\n\t}\n\n\t\/** If you want to use the number in your logic, this is where you&#039;d do it.\n\t * Make sure you return as part of this, so you don&#039;t call the function at the end and undo your changes!\n\t *\/\n\n\t\/\/ If we&#039;re not doing any logic up above, just make sure your desired changes are in the $custom_text array above (in the `tribe_custom_theme_text` filter. )\n\tif ( 1 === $number ) {\n\t\treturn tribe_custom_theme_text ( $translation, $single, $domain );\n\t} else {\n\t\treturn tribe_custom_theme_text ( $translation, $plural, $domain );\n\t}\n}\n\n\n\nfunction tribe_custom_theme_text_with_context ( $translation, $text, $context, $domain ) {\n\t\/\/ If this text domain doesn&#039;t start with &quot;tribe-&quot;, &quot;the-events-&quot;, or &quot;event-&quot; bail.\n\tif ( ! check_if_tec_domains( $domain ) ) {\n\t\treturn $translation;\n\t}\n\n\t\/** If you want to use the context in your logic, this is where you&#039;d do it.\n\t * Make sure you return as part of this, so you don&#039;t call the function at the end and undo your changes!\n\t * Example (here, we don&#039;t want to do anything when the context is &quot;edit&quot;, but if it&#039;s &quot;view&quot; we want to change it to &quot;Tribe&quot;):\n\t * if ( &#039;edit&#039; === strtolower( $context ) ) {\n\t *    return $translation;\n\t * } elseif( &#039;view&#039; === strtolower( $context ) ) {\n\t *    return &quot;Tribe&quot;;\n\t * }\n\t *\n\t * Feel free to use the same logic we use in tribe_custom_theme_text() above for key =&gt; value pairs for this logic.\n\t *\/\n\n\t\/\/ If we&#039;re not doing any logic up above, just make sure your desired changes are in the $custom_text array above (in the `tribe_custom_theme_text` filter. )\n\treturn tribe_custom_theme_text ( $translation, $text, $domain );\n}\n\n\n\nfunction tribe_custom_theme_text_plurals_with_context ( $translation, $single, $plural, $number, $context, $domain ) {\n\t\/\/ If this text domain doesn&#039;t start with &quot;tribe-&quot;, &quot;the-events-&quot;, or &quot;event-&quot; bail.\n\tif ( ! check_if_tec_domains( $domain ) ) {\n\t\treturn $translation;\n\t}\n\n\t\/**\n\t * If you want to use the context in your logic, this is where you&#039;d do it.\n\t * Make sure you return as part of this, so you don&#039;t call the function at the end and undo your changes!\n\t * Example (here, we don&#039;t want to do anything when the context is &quot;edit&quot;, but if it&#039;s &quot;view&quot; we want to change it to &quot;Tribe&quot;):\n\t * if ( &#039;edit&#039; === strtolower( $context ) ) {\n\t *    return $translation;\n\t * } elseif( &#039;view&#039; === strtolower( $context ) ) {\n\t *    return &quot;cat&quot;;\n\t * }\n\t *\n\t * You&#039;d do something as well here for singular\/plural. This could get complicated quickly if it has to interact with context as well.\n\t * Example:\n\t * if ( 1 === $number ) {\n\t *    return &quot;cat&quot;;\n\t * } else {\n\t *    return &quot;cats&quot;;\n\t * }\n\t * Feel free to use the same logic we use in tribe_custom_theme_text() above for key =&gt; value pairs for this logic.\n\t *\/\n\n\t\/\/ If we&#039;re not doing any logic up above, just make sure your desired changes are in the $custom_text array above (in the `tribe_custom_theme_text` filter. )\n\tif ( 1 === $number ) {\n\t\treturn tribe_custom_theme_text ( $translation, $single, $domain );\n\t} else {\n\t\treturn tribe_custom_theme_text ( $translation, $plural, $domain );\n\t}\n}\n\nfunction check_if_tec_domains( $domain ) {\n\t$is_tribe_domain = strpos( $domain, &#039;tribe-&#039; )      === 0;\n\t$is_tec_domain   = strpos( $domain, &#039;the-events-&#039; ) === 0;\n\t$is_event_domain = strpos( $domain, &#039;event-&#039; )      === 0;\n\n\t\/\/ If this text domain doesn&#039;t start with &quot;tribe-&quot;, &quot;the-events-&quot;, or &quot;event-&quot; bail.\n\tif ( ! $is_tribe_domain &amp;&amp; ! $is_tec_domain &amp;&amp; ! $is_event_domain ) {\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n\n\/\/ Base.\nadd_filter( &#039;gettext&#039;, &#039;tribe_custom_theme_text&#039;, 20, 3 );\n\/\/ Plural-aware translations.\nadd_filter( &#039;ngettext&#039;, &#039;tribe_custom_theme_text_plurals&#039;, 20, 5 );\n\/\/ Translations with context.\nadd_filter( &#039;gettext_with_context&#039;, &#039;tribe_custom_theme_text_with_context&#039;, 20, 4 );\n\/\/ Plural-aware translations with context.\nadd_filter( &#039;ngettext_with_context&#039;, &#039;tribe_custom_theme_text_plurals_with_context&#039;, 20, 6 );\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>The featured&nbsp;snippet here will help you change any piece of text in The Events Calendar and its add-ons. With a little bit of modification, it would even allow you to change the wording of any piece of text anywhere in WordPress, not just this plugin! First copy\/paste the snippet at the bottom of this page&#8230;<\/p>\n","protected":false},"author":17,"featured_media":1955565,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","_swpsp_post_exclude":false,"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"ep_exclude_from_search":false,"footnotes":""},"categories":[79],"tags":[20,25,58,92],"stellar-product-taxonomy":[161],"class_list":["post-1896507","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-snippets","tag-code","tag-customizations","tag-php","tag-translations","stellar-product-taxonomy-the-events-calendar"],"acf":[],"taxonomy_info":{"category":[{"value":79,"label":"Snippets"}],"post_tag":[{"value":20,"label":"Code"},{"value":25,"label":"Customizations"},{"value":58,"label":"PHP"},{"value":92,"label":"Translations"}],"stellar-product-taxonomy":[{"value":161,"label":"The Events Calendar"}]},"featured_image_src_large":["https:\/\/images.theeventscalendar.com\/kb\/uploads\/2023\/02\/social-share-1024x538.png",1024,538,true],"author_info":{"display_name":"Andras Guseo","author_link":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/author\/andras\/"},"comment_info":0,"category_info":[{"term_id":79,"name":"Snippets","slug":"snippets","term_group":0,"term_taxonomy_id":79,"taxonomy":"category","description":"","parent":0,"count":136,"filter":"raw","term_order":"0","cat_ID":79,"category_count":136,"category_description":"","cat_name":"Snippets","category_nicename":"snippets","category_parent":0}],"tag_info":[{"term_id":20,"name":"Code","slug":"code","term_group":0,"term_taxonomy_id":20,"taxonomy":"post_tag","description":"","parent":0,"count":33,"filter":"raw","term_order":"0"},{"term_id":25,"name":"Customizations","slug":"customizations","term_group":0,"term_taxonomy_id":25,"taxonomy":"post_tag","description":"","parent":0,"count":177,"filter":"raw","term_order":"0"},{"term_id":58,"name":"PHP","slug":"php","term_group":0,"term_taxonomy_id":58,"taxonomy":"post_tag","description":"","parent":20,"count":128,"filter":"raw","term_order":"0"},{"term_id":92,"name":"Translations","slug":"translations","term_group":0,"term_taxonomy_id":92,"taxonomy":"post_tag","description":"","parent":0,"count":16,"filter":"raw","term_order":"0"}],"_links":{"self":[{"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1896507","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/comments?post=1896507"}],"version-history":[{"count":1,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1896507\/revisions"}],"predecessor-version":[{"id":1956305,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/posts\/1896507\/revisions\/1956305"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/media\/1955565"}],"wp:attachment":[{"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/media?parent=1896507"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/categories?post=1896507"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/tags?post=1896507"},{"taxonomy":"stellar-product-taxonomy","embeddable":true,"href":"https:\/\/staging.theeventscalendar.com\/knowledgebase\/wp-json\/wp\/v2\/stellar-product-taxonomy?post=1896507"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}