anttiviljami / wp-pdf-templates

Add PDF templates to your WordPress theme
https://wordpress.org/plugins/wp-pdf-templates
GNU General Public License v3.0
42 stars 18 forks source link

a proper way to override _locate_pdf_template #30

Open pooledge opened 7 years ago

pooledge commented 7 years ago

Dear Viljami, thanks for a great plug-in! It rocks. Not really an issue. But how would you suggest to intercept add_filter('template_include', '_locate_pdf_template') to return same fixed path no matter what?

This is how i'm doing it now – theme's functions.php:

// PDF template handling
add_filter('template_include', 'theme_locate_pdf_template', 11);
function theme_locate_pdf_template($template) {
    global $wp_query;
    if (isset($wp_query->query_vars['pdf-template'])) {
        $template = get_template_directory() . '/pdf/pdf.php';      
    }
    return $template;
}
bouveng commented 1 year ago

@pooledge Thanks for this! Adding a higher priority makes it works with page builders, like elementor, that replaces templates for woocommerce, while still maintaining the regular non-pdf-template :rocket: