WordPress.org

Ready to get started?Download WordPress

Forums

How to use 'Template Name:' in plugins? (2 posts)

  1. Kenth Hagström
    Member
    Posted 1 year ago #

    I'm using the Template Name: comment tag in a file located in my plugins root directory, see code below. But WordPress refuses to recognize this page template. Do I have to include the file somehow inside my plugin? I do not want the user to manually create files in the theme directory to get things running, it should work 'out of the box'. There must be an easier way, right?

    <?php
    /*
    Template Name: MyPageTemplate
    */
    // more code...
  2. Chris
    Member
    Posted 1 year ago #

    Not that I'm aware of. There are good reasons why plugins and themes (+templates) are separate entities.

    Though there is a black hat way to achieve this. And I mean "black hat" because no one likes it if someone else messes with your product/theme/code. All kinds of things could happen!

    If you still insist, get the current theme's directory and if your page template file does not exists there, copy it from your plugin directory to that destination.

    But again, this could go ugly and backfire on you in so many ways I would not recommend doing it

Topic Closed

This topic has been closed to new replies.

About this Topic