Support » Developing with WordPress » Custom single post template following user

  • Hello,
    It’s been a long time I didn’t come to the forum… hope you’ll be able to help me.
    I’m trying to create a custom single post template that would be used only if the posts are seen by a specific user.

    For those who are interested here is the reason : I have a website presenting about 300 products (custom post type : product). I need to export all product detailed pages as PDF to use them as factsheets (for our salesmen) without the website Header, Footer, sidebar…
    I found a way to create PDF from URLs thanks to Acrobat Pro which has this functionality : create a PDF or a list of PDF from url. I tried, it works, but of course, it renders the pdfs as they are shown in the browser : with all unnecessary parts (header, sidebar, links, footer,…). (it could have been the print version of the page which is already set to show only the interesting parts thanks to CSS).
    So I thought I might create a “light” version of the single-product template and call that template instead of the regular one. This is where I’m stuck : Find a way to show the light version of the products, just to generate PDFs.
    I thought there would be a way to tell wordpress to use the regular single product template for all visitors and the light version if I’m logged as a registered user called for example “PDF-Visitor”. But I can’t figure out how to do that.

    Sorry for my english and to write long sentences, I hope it’s clear enough to understand what I need.


    • This topic was modified 9 months, 1 week ago by  trouille2.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz


    There are actually several ways to handle this, each involves a different user experience. I think the most logical is to use CSS to set all the unnecessary elements to display: none; in the print only CSS media query section. When any user chooses to print the page, none of the unnecessary elements will show on the printout. Users could select print to PDF to get PDF files of the printout.

    If you still want to manage who can print a plain, unadorned version of the page, the print only CSS media query could be in a separate CSS file that is only enqueued when the user is logged in and has a particular capability. Without this file, printing the page will result in the normal default behavior.

    Hi bcworkz,
    I think by two ideas that were not initially what I was looking for, indirectly, it make me think of a solution, or maybe was it your meaning.
    I use already the CSS print version, and have a “Print to PDF” button on each product page, but this way, I need to visit every pages and download them manually.
    As my goal is to batch a “create a pdf from all product pages” in one time (via Acrobat pro). I think by replicating the CSS print version as a media:screen version and use it for the specific user, it will override the regular CSS and show me the desired version of the template only if this regular user is logged. This is doable. Good idea. I’ll try this.

    Nope, it doesn’t work,
    I’ve enqued a new CSS when one user id is logged. the pages are well rendered, but when I ask Acrobat Pro to create PDF from URLs, Acrobat seems not to use any browser so it download the page as unlogged user, so it download the regular page… Maybe if I pass a variable in the url, I can activate the special CSS when the variable is in the URL…

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom single post template following user’ is closed to new replies.