• This is a two part question:

    1: Should I create a new template for pages that are slightly different?
    Is it more useful to create a template for each page or use one continually? For example, An “about” page Could use the same template as a “contact” page, but are there benefits or drawbacks to creating a template for “about” and a template for “contact”?

    2: Should I add scripts on a per template level?
    Is it better to include scripted functionality into a template than to rely on a plugin?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    An “about” page Could use the same template as a “contact” page, but are there benefits or drawbacks to creating a template for “about” and a template for “contact”?

    If you named the template something ambiguous like “single-column” rather than “about” or “contact” then there wouldn’t be any reason not to. But this is entirely specific to your templates and how different they are on different pages.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    2: Should I add scripts on a per template level?
    Is it better to include scripted functionality into a template than to rely on a plugin?

    They are separate questions. You shouldn’t really add scripts into templates but instead enqueue them from your functions.php file, or if you don’t want to code and find a plugin that does it for you use that instead.

    Thread Starter Sean Manion

    (@seanmanion)

    Regarding the response to question 2: Due to the inability to rely on every plugin coder to properly enqueue (resulting in unwanted scripts on pages not using those scripts), then why how is adding a script ‘per template’ bad? Also, if enqueueing, then won’t that be messed up when the plugin updates?

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Due to the inability to rely on every plugin coder to properly enqueue (resulting in unwanted scripts on pages not using those scripts), then why how is adding a script ‘per template’ bad?

    Adding a script per template and enqueing results in the same outcome. Adding a script per template is bad because it’s difficult to manage and can lead to code being called in the wrong places.

    Also, if enqueueing, then won’t that be messed up when the plugin updates?

    Which plugin are you talking about? Why would enqueing something be more dangerous than not enqueing?

    Thread Starter Sean Manion

    (@seanmanion)

    I am asking because plugins used are creating a large number of http requests. Adding scripted functionality to Only the page that needs the functionality (via template) is the solution I suggest. It is not clear how adding scripted functionality to Only the page that needs the functionality (via template) would ‘lead to code being called in wrong places’.

    Which plugin are you talking about? Why would enqueing something be more dangerous than not enqueing?

    Didn’t say ‘dangerous’. I do not understand how the enqueue would remain when the plugin updates..

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    It is not clear how adding scripted functionality to Only the page that needs the functionality (via template) would ‘lead to code being called in wrong places’.

    Ah that’s the confusion, I’m all for template-specific scripts but the difference is I’m saying enqueue them instead of hardcode them.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Didn’t say ‘dangerous’. I do not understand how the enqueue would remain when the plugin updates.

    I’m not trying to misquote you, honest ?? It depends where you’re enqueing them: In the example that the plugin supports Child Theme customisations, like WooCommerce, you can dequeue the plugin’s scripts in your Child Theme functions.php file and then enqueue your own. Then when the plugin updates, as long as the plugin still enqueues its scripts, you will still be able to dequeue them (and enqueue your own).

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Template per Page/Script per Template. Useful or No?’ is closed to new replies.