@spinoops this is what I did to replace words in the English event pages. It’s not the best solution but it works.
Add this to your functions.php in child theme.
function replace_words_on_en_events_pages() {
$current_url = $_SERVER['REQUEST_URI'];
if (strpos($current_url, '/en/events/') !== false) { ?>
<script>
// Function to replace words on the page
function replaceWordsOnEnEventsPages() {
// Define the words and their replacements
const wordReplacements = {
"Ajouter au calendrier": "Add to Calendar",
"Date de l’événement": "Event Date",
"Heure de l’événement": "Event Time",
"Partager l’événement": "Share",
"Inscrivez-vous": "Register",
"Acheter": "Buy Now"
// Add more word replacements as needed
};
// Select the content container where you want to perform the replacements using class
const contentContainers = document.querySelectorAll(".mep-events-container");
// Loop through each content container and perform the replacements
contentContainers.forEach((container) => {
let content = container.innerHTML;
// Loop through the word replacements and perform the replacements
for (const [searchWord, replacement] of Object.entries(wordReplacements)) {
const regex = new RegExp(searchWord, "gi"); // "gi" means global and case-insensitive
content = content.replace(regex, replacement);
}
// Set the modified content back to the container
container.innerHTML = content;
});
}
// Call the replaceWordsOnEnEventsPages function when the page is loaded
document.addEventListener("DOMContentLoaded", replaceWordsOnEnEventsPages);
</script>
<?php }
}
add_action('wp_footer', 'replace_words_on_en_events_pages');
-
This reply was modified 1 year, 3 months ago by kpatelneha23.