Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@yanknudtskov
Last active October 4, 2023 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yanknudtskov/c23ea7f308ccfcc42374f339947a8e95 to your computer and use it in GitHub Desktop.
Save yanknudtskov/c23ea7f308ccfcc42374f339947a8e95 to your computer and use it in GitHub Desktop.
Override The Events Calendar Plugin templates for events.Remember to copy the files/wp-content/themes/enfold/config-events-calendar/views/default-template.php/wp-content/themes/enfold/config-events-calendar/views/single-event.phpinto/wp-content/themes/enfold_child_theme_by_yanco/views/default-template.php/wp-content/themes/enfold_child_theme_by_…
<?php
add_action( 'after_setup_theme', 'enfold_child_theme_code' );
function enfold_child_theme_code() {
if(is_child_theme()) remove_action('tribe_events_template', 'avia_events_template_paths', 10, 2);
}
add_action('tribe_events_template', 'avia_events_template_paths_mod', 10, 2);
function avia_events_template_paths_mod($file, $template)
{
$redirect = array('default-template.php', 'single-event.php');
if(in_array($template, $redirect))
{
$file = get_stylesheet_directory() . "/tribe-events/views/".$template;
}
return $file;
}
@AscendTraining
Copy link

Typo line 5, should be 'avia_events_template_paths'
Otherwise thanks!

@yanknudtskov
Copy link
Author

Thanks :-)

Typo line 5, should be 'avia_events_template_paths'
Otherwise thanks!

@alshedupur
Copy link

alshedupur commented Oct 4, 2023

To ensure safe usage, this code is designed to prioritize template files in your child theme. If no custom template files exist in the child theme, it will fall back to using the template files from the Enfold main theme.

add_action('after_setup_theme', 'enfold_child_theme_code');
function enfold_child_theme_code() {
    if (is_child_theme()) {
        remove_action('tribe_events_template', 'avia_events_template_paths', 10, 2);
    }
}
add_action('tribe_events_template', 'avia_events_template_paths_mod', 10, 2);
function avia_events_template_paths_mod($template, $template_name) {
    $child_theme_path = get_stylesheet_directory() . "/tribe-events/views/" . $template_name;
    $parent_theme_path = get_template_directory() . "/config-events-calendar/views/" . $template_name;

      if (file_exists($child_theme_path)) {
          return $child_theme_path;
      } elseif (file_exists($parent_theme_path)) {
          return $parent_theme_path;
      }
    return $template;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment