addressalign-toparrow-leftarrow-leftarrow-right-10x10arrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscontroller-playcredit-cardcrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobe--smallglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1languagelaunch-new-window--smalllight-bulblightning-boltlinklocation-pinlockm-swarmSearchmailmediummessagesminusmobilemoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonprintShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstar-shapestartickettrashtriangle-downtriangle-uptwitteruserwarningyahooyoutube

Conditional Tags vs Page Templates?

From: Jason C.
Sent on: Tuesday, April 5, 2016, 3:40 PM
Hello Fellow WordPressers,

I have what may be a bit of a philosophical question: When adding custom functionality to your site, is it better to use conditional tags or create a new template (either named based on the Template Heirarchy or custom page template)?

For instance: 
Say I've added a custom post type, "custom". I want to do some cool stuff with both its "single" page and it's "archive" page. 

From a Coding Best Practices standpoint

a) is it better to write a function in functions.php such as:
// Customize Custom Post Type
add_action('wp-head', 'my_custom_function');

function my_custom_function(){
if (is_post_type_archive('custom')){
"Do custom stuff like replace loop, etc"
}
}

or
b) should I create a separate archive-custom.php file (or single-custom.php, etc) and do all the customization there?

---

I tend to do both, but as I'm constantly trying to improve the efficiency of my coding, I'm wondering if there's a "Best Practices" approach I should follow. 

Does anyone have an opinion either way?

Thanks,
-Jason Chafin

People in this
group are also in: