Home > database >  Edit php to replace a line of text
Edit php to replace a line of text

Time:03-26

I am working on a WordPress development with a theme where a Button has hardcoded text I want to change. I am using a child theme and am hoping there is a way to add some PHP to the functions file to display wording on the button different from the hardcoded text. The theme code is:

if ( ! function_exists( 'boldthemes_get_book_this_tour_button_label' ) ) {
        function boldthemes_get_book_this_tour_button_label(){
            if ( BoldThemesFrameworkTemplate::$tour_contact_form_booking_show) {
                return esc_html__( 'Book this Tour', 'travelicious' );
            } else if ( BoldThemesFrameworkTemplate::$tour_contact_form_enquiry_show ) {
                return esc_html__( 'Enquiry about the Tour', 'travelicious' );
            } else{
                return esc_html__( 'Sorry! There are no enabled booking or enquiry forms.', 'travelicious' );
            }
       }
}

I only need to edit the else if line so that it says 'Enquire about this Trip' instead of 'Enquiry about the Tour'

I have tried a str_replace and it did change the text but threw a conflict error with the theme so am wondering if I either did not set it out correctly or if there is an alternative method? The theme developer recommended adding a translation to the theme but that to me seems a bit heavy just to change a couple of words.

Thanks

CodePudding user response:

One way you could do this is to hook into esc_html like so:

// place in your functions.php
add_filter("esc_html", function($text) {
    if ("Enquiry about the Tour" === $text) {
        return "Enquire about this Trip";
    }

    return $text;
});
  • Related