• Colin

    (@colinsafranek)


    I’d like to be able to apply a landscape orientation to just one specific template, or based on a custom post meta value.

    In the FAQ you show the example of changing the orientation setting globally via the wp-config file, but I was wondering if it’s possible to set just one specific template to be landscape, and leave the rest as the default portrait?

    Thanks!

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Viljami Kuosmanen

    (@zuige)

    Sure! You can define the orientation in an action hook somewhere else, just before the pdf run.

    For example in your functions.php:

    add_filter( 'template_include', '_choose_orientation');
    function _choose_orientation( $template ) {
      if ( basename( $template ) === 'portrait-template-pdf.php' ) {
        define('DOMPDF_PAPER_ORIENTATION', 'portrait');
      } else {
        define('DOMPDF_PAPER_ORIENTATION', 'landscape');
      }
      return $template;
    }

    Code above is not actually tested, but should in theory work.

    Thread Starter Colin

    (@colinsafranek)

    FYI this does not work for me. I’ve confirmed that the correct template is being used by printing echo basename( get_page_template() ); from within the pdf template in question. I tried testing for both the page template and the pdf page template, neither tests returned true, therefore paper orientation always defaulted to the value defined in the else statement.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Landscape orientation on specific template?’ is closed to new replies.