• Hi,

    First, thanks for this really useful plugin!

    I have a custom template named single-post.php for posts. I created a single-post-pdf.php to handle the pdf version of a post. When I test it with the pdf-template endpoint, it loads ok. But if I try to load using both pdf and pdf-preview, the template doesn’t load, it just loads the page into the pdf as it doesn’t exist any template. Even using index-pdf.php, the result is the same.

    I’ve already disabled cache using define('DISABLE_PDF_CACHE', true); in wp-config, but the result is the same.

    Any ideas of what could be wrong?

    Thanks for any answer!

    https://www.ads-software.com/plugins/wp-pdf-templates/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Diego de Oliveira

    (@diegoliv)

    Hi! I’ve just found the issue. I have some custom code to prefix all my posts with a custom string. Check it out:

    // add rewrite rule for infobase prefix
    add_action( 'generate_rewrite_rules', 'custom_add_rewrite_rules'  ); 
    
    function custom_add_rewrite_rules( $wp_rewrite ) {
         $new_rules = array( 'infobase/(.+?)/?$' => 'index.php?post_type=post&name='. $wp_rewrite->preg_index(1) );
    
         $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
    }
    
    // prefix blog links
    add_filter( 'post_link', 'custom_change_blog_links', 1, 3 ); 
    
    function custom_change_blog_links( $post_link, $id = 0 ){
    
         $post = get_post( $id );
         if( is_object( $post ) && $post->post_type == 'post' ){
              return home_url( '/infobase/'. $post->post_name .'/ ');
         }
    
         return $post_link;
    }

    After I removed this code, the plugin worked fine!

    Do you have any suggestion about how to make this custom code work with the plugin? If not, that’s fine, I’ll leave it as it is for now.

    Thanks!

    Plugin Author Viljami Kuosmanen

    (@zuige)

    Glad you could make it work!

    I think the issue lies with how you define your custom rewrite rules. Please refer to the official WordPress documentation on the recommended way of how to add rewrite rules to your site.

    https://codex.www.ads-software.com/Rewrite_API/add_rewrite_rule/

    Cheers!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘pdf-template loads template ok, pdf-preview and pdf not’ is closed to new replies.