[Resolved] Conditional page header template tags?

Home Forums Support [Resolved] Conditional page header template tags?

Home Forums Support Conditional page header template tags?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #763259
    Scrat

    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.

    #763371
    Tom
    Lead Developer
    Lead Developer

    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 ๐Ÿ™‚

    #810777
    Brad

    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

    #810843
    Tom
    Lead Developer
    Lead Developer

    Great to hear! ๐Ÿ™‚

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.