Free and Premium WordPress Plugins & Themes Forums WordPress Plugins Hotel Booking How to override template functions
- This topic has 3 replies, 4 voices, and was last updated 6 years, 2 months ago by J. Davis.
- AuthorPosts
- October 5, 2018 at 9:43 am #726815Nicolas KuhnParticipant
Hi,
Is there a way to override php functions located in the template-functions.php file at the plugin directory root ?
An example would be the mphb_tmpl_the_room_reservation_form() function as I would like to rename the “Confirm reservation” button… I could modify it directly in this file but then I lose all plugin upgrading ability as it would overwrite any change in native plugin files I suppose…
Thanks!
NicolasOctober 5, 2018 at 2:10 pm #726936Stacy LindKeymasterHi Nicolas,
The file template-functions.php cannot be overridden. We do not recommend editing the plugin files. Renaming can be done easier and safer with a translation plugin:
1. Install a translation plugin e.g. Loco Translate from wp.org and activate it.
2. Navigate to Dashboard > Loco Translate > Plugins and click Hotel Booking.
3. Click New Language.
4. Choose the language of your WordPress.
5. Use the filter field to find all strings with phrases that you want to change.
6. Insert your own phrases as translation.
7. Save and check the result.This way the change will not be lost during update.
October 24, 2018 at 3:59 pm #733503Manuel SosiParticipantHi!
and what about if we need/want to override a function? like for example if we would like 3 columns instead of 4 in template-functions.phpfunction mphb_tmpl_the_single_room_type_gallery(){
$galleryAtts = array(
‘link’ => apply_filters( ‘mphb_single_room_type_gallery_image_link’, ‘file’ ),
‘columns’ => apply_filters( ‘mphb_single_room_type_gallery_columns’, ‘4’ ),
‘size’ => apply_filters( ‘mphb_single_room_type_gallery_image_size’, ‘thumbnail’ ),
‘mphb_wrapper_class’ => apply_filters( ‘mphb_single_room_type_gallery_wrapper_class’, ‘mphb-single-room-type-gallery-wrapper’ )
);mphb_tmpl_the_room_type_galery( $galleryAtts );
}October 26, 2018 at 12:00 pm #734132J. DavisKeymasterHi Manuel,
Thank you for your question. You may modify it by adding filters e.g.:
add_filter( 'mphb_single_room_type_gallery_columns', 'theme_mphb_single_room_type_gallery_columns' ); function theme_mphb_single_room_type_gallery_columns() { return 3; }
best regards,
J. Davis - AuthorPosts
- You must be logged in to reply to this topic.