WordPress.org

Ideas

locate_template should also look into the plugin directory

  1. lerizzle
    Member

    It would be nice if locate_template() would look last in the plugin directory for templates to load if it didn't find it in the other 2 spots.

    Posted: 5 years ago #
  2. Stefan Matei
    Member

    12345

    Yes, that would be great!

    I was currently looking for a workaround myself.

    Posted: 5 years ago #
  3. Hal Gatewood
    Member

    Here is my current structure:

    // LOOK FOR TEMPLATE IN THEME
    $template = locate_template( array( "loop-article-slug.php", "loop-article.php" ) );

    // LOOK IN PLUGIN
    if( !$template )
    {
    $template = dirname(__FILE__) . "/loop-article.php";
    }

    // LOAD TEMPLATE
    if( $template )
    {
    include( $template );
    }

    Posted: 3 years ago #
  4. nineproof
    Member

    +1

    Posted: 4 months ago #
  5. Ipstenu (Mika Epstein)
    Lead Plugin Wrangler

    The problem there is you'd have to code it to only look for active plugins, and on a multisite that becomes a metric level of slow.

    Looking within a plugin is best done by the plugin itself, which checks first if the template is in the theme and if not, uses the plugin.

    So it's backward to what you're thinking, but that's the more dependable and less random version.

    Posted: 4 months ago #
  6. marco.marsala
    Member

    No. Just need to check the plugin where the function is called from.

    Brw, how you would check for overridden template files in plugin code? Currently I'm using file_exists but it sounds like a bad programming practice... What do you think?

    Posted: 4 months ago #

RSS feed for this topic

Reply

You must log in to post.

  • Rating

    12345
    5 Votes
  • Status

    This idea is under consideration