WordPress.org

Ideas

More filters in general-template.php functions

  1. Phil Smart
    Member

    I'd like to suggest adding filters to functions such as;
    get_header(), get_footer(), get_sidebar(), and get_template_part(), so that we can override/disable the template being called without having to actually create template files.

    I can see an action in each, allowing us to carry out specific actions on a particular template call, but no filter – a problem if we aren't using the default procedural approach to working with WordPress. What I do like is the template_include filter in template-loader.php, as it enables this kind of behaviour for main template files.

    Why I think this would be handy?

    Many plugins (specifically eCommerce such as WooCommerce) rely on overriding the templates to load their specific markup. This means that they load up their own templates for their own custom post types and that those templates include calls to their own headers and footers.

    Please note: I'm aware I can override these template files by declaring them in a custom theme, but I don't consider that the wisest approach, as it means replicating a lot of code to achieve something fairly trivial.

    Just to give you an idea – I work with my own theme base for custom development that takes a similar approach to Genesis in that it invokes a function, within a template file, to execute the front end components. This basically means that there is no need for me to call get_header() or get_footer() in templates, as those calls are handled as part of the load process, and it also means I can utilise the template file as a template-specific functions.php file (albeit, a very late one). This works really well for my and my class-oriented, OOP approach to custom theme development. But, it falls down when plugins use their own templates, as the standard page load is never invoked by those plugins.

    My current workaround is to create blank header-XXX.php and footer-XXX.php files to override the plugin call, then start an output buffer that captures everything for insertion into my own load sequence. If there were some adequate filters that allowed me to disable the calls to get_header() and get_footer(), I wouldn't need blank template files and could rely solely on a simple compatibility class that autoloads at the detection of certain plugins.

    I know that might be a bit specific to my needs, but I'm sure there must be other devs who have come up against similiar issues.

    Thanks for reading!

    Posted: 12 months ago #

RSS feed for this topic

Reply

You must log in to post.

  • Rating

    12345
    1 Vote
  • Status

    This idea is under consideration