Config Sidebar Template Wildcard "template-*.php"

Just curious if this is possible…

On config where you declare the templates that should not display a sidebar, is there a way to use a wilecard here?

I have a few templates that carry the same root name “work-…” and it would be awesome to use something like "work-*.php here if possible.

In this case it’s not a big deal. I have 3 templates to write in but if this came up in the future I’d like to put this to good use.

function roots_display_sidebar() {
  $sidebar_config = new Roots_Sidebar(
    /**
     * Conditional tag checks (http://codex.wordpress.org/Conditional_Tags)
     * Any of these conditional tags that return true won't show the sidebar
     *
     * To use a function that accepts arguments, use the following format:
     *
     * array('function_name', array('arg1', 'arg2'))
     *
     * The second element must be an array even if there's only 1 argument.
     */
    array(
      'is_404',
      'is_front_page'
    ),
    /**
     * Page template checks (via is_page_template())
     * Any of these page templates that return true won't show the sidebar
     */
    array(
      'work.php',
      'work-*.php',
    )
  );

  return apply_filters('roots_display_sidebar', $sidebar_config->display);
}

Thanks!

There’s no way to currently do this and it isn’t really possible. is_page_template requires the exact filename to check so without explicitly listing them, there’s no way to know what it is.

Scott’s correct in saying that is_page_template can’t accommodate wildcards, but you could create your own boolean function and reference it as a callback in the first array.

Hi guys, i added is_page(id), but it doesnt work.
I am doing it wrong?

array(
  'is_404',
  'is_front_page',
  'is_page(9)'
),

You need to pass the function and the argument as an array. There’s an example in the code’s comments or a more comprehensive guide here.

Thanks!, now it’s working, that guide help me c: