• HI guys,

    Is there a built in WordPress function that returns the name of the page template that is being displayed? Much like, is_page(‘pagename’), but more like, is_template(‘template’) – I tried this but it didn’t work!

    If no such thing exists, is there some variable exposed that will let me test what template is being viewed?

    Thanks very much

    Andy.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Do you mean Page template? or just any template?
    Actually I don’t know the answer – all the Conditional_Tags are at this link.
    If it’s about Page templates – Pages use the template you select or… according to Template_Hierarchy.

    Thread Starter andyhume

    (@andyhume)

    Yeah, I mean page template. So I can do different things in say, header.php, depending on what template is being used.

    I’ve actually found a way of doing this aftyer digging through functions.php for a bit. get_page_template() returns the name of the template but with the entire absolute address of the server as well. So it’s a bit long winded, but is doing the job! ??

    There really should be a nice clean function to find what page template you are using though. As I suggest earlier:

    is_template(‘name’) would be good.

    There really should be a nice clean function to find what page template you are using though.

    Any Page assigned a template retains it in the ‘_wp_page_template’ custom field. Here’s your function:

    https://paste.uni.cc/8446

    Note I call the function is_page_template() to clarify use (and avoid conflict with any is_template() function appearing later). If running WordPress 2.0, you can drop this in a functions.php file and save it with your active theme, and WordPress will automatically include it.

    Thread Starter andyhume

    (@andyhume)

    Nice one Kafkaesqui. That’s exactly what I was looking for. Cheers.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Conditional template tag’ is closed to new replies.