Site logo

Archived topic

Conditional page header template tags?

3 replies · Started by Scrat on December 21, 2018

Viewing posts 1–4 of 4

Hello! I was just wondering if it's possible to put some logic in the page headers. I'd like to be able to print a custom field if it exists and fall back to the page title if it doesn't. So like {{custom_field.display_title}} ? {{custom_field.display_title}} : {{page_title}}, if that makes sense.

Hi there,

Currently we don't support conditionals, but it's something on our roadmap.

What you can do is create a shortcode:

add_shortcode( 'hero_title', function() {
    $custom = get_post_meta( get_the_ID(), '_your_custom_title', true );
    $title = get_the_title();

    if ( $custom ) {
        return $custom;
    }

    if ( $title ) {
        return get_the_title();
    }
} );

Then you'd use this in the hero: [hero_title]

Let me know if that helps or not :)

Hey Tom - I was trying to do the same thing as I wanted the Global Page header text in an element to be something other than the page name. Created a custom Field in AFC and used your code..Worked Perfectly..

Thank You

Great to hear! :)

This archived topic is closed to new replies.