We want to test different landing pages to display only certain parts of a specific Custom Post Type's content metadata so I need to create templates that are used only when specifically crafted URLs are clicked on, that will not be linked to anywhere from the website.

I am not looking to change the default WP behavior for loading single pages (the current various single-cpt.php templates) because we want all current behavior to remain the same for anyone on the site who clicks on various links - the new landing pages will be linked to from other sites so if the site visitor clicks on one of those off-site links I want to be able to serve them up the content using a specific (single) template file.

I could, in theory, just create new Posts for those landing pages but that means that if the content changes now I have TWO Posts to update or risk incorrect content being displayed, so I want to avoid that by having the same content called by both the normal template and the new 'landing' template.

I've done a lot of research into using various templates for custom post types and taxonomies and the idea of adding yet another term (this particular CPT has a Custom Taxonomy also setup with a number of terms in use) and can get as far as a custom taxonomy archive-style template that works, but not a single template that I can get to work without interfering with normal behavior.

I'm open to any/all suggestions!

  • 1
    Sounds like you want to do A/B tests, have you looked into how plugins do this right now?
    – kero
    Jul 2, 2018 at 22:39
  • Thanks @kero, but it isn't exactly A/B testing, and the plugins I did look at seem to send traffic in a randomized way to the different pages - what we want to do is send specific traffic to specific pages without changing the experience for (normal) site visitors - those that don't get to the site via these specific links but find their way there via other links or SERPs
    – Trisha
    Jul 3, 2018 at 17:45

1 Answer 1


You can add a query string to your URLs and read that using the $_GET global.

For example, you could add ?template=main to your posts's URL. Then, in the single-cpt.php for your CPT, use

<?php if ( isset( $_GET['template'] ) ) $mytemplate = $_GET['template']; ?>

Then, around the bits that you want to display differently, just add

switch ( $mytemplate ):
    case "main":
    case "somethingelse":

Oh, and to add the query string to your URLs in the first place, use:

$url = add_query_arg( 'template', 'main', $permalinktopost );

Hope that helps

  • Perfect! A creative, simple, and elegant solution that works. Thank you @Peter HvD I greatly appreciate your help!
    – Trisha
    Jul 4, 2018 at 17:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.