Site logo

[Resolved] Write PHP inside custom page headers?

Home Forums Support [Resolved] Write PHP inside custom page headers?

Home Forums Support Write PHP inside custom page headers?

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #620903
    George

    Just experimenting with the new 1.7 beta custom header element and came to a point where I would like to conditionally display a shortcode inside a header only on certain pages. The actual hero page header that includes the shortcode has already display contitions set. I just want the shortcode that resides inside the header text not to be displayed on single post items. Right now I have to create two identical headers, one with the shortcode included and one with the shortcode excluded and assign them different conditionals. Is there a way to hook content into the custom page header somehow? Or would it make sense to consider adding the possibility to be able to write PHP code inside the custom page header element in a future release?

    #621327
    Tom
    Lead Developer
    Lead Developer

    Hey George,

    I’m not 100% sold on allowing PHP inside Page Heros. To be honest, I’m not 100% sold on it in Hooks either. Still thinking about the best road to take there.

    Right now the Page Hero is filterable (in beta.2), so we would be able to filter in your code quite easily.

    I’ll also look at adding a hook into the Page Hero, as I think that would be very helpful 🙂

    #621340
    George

    I trust you 100% that you will find the best solution possible, Tom! Thank you.

    #621617
    Tom
    Lead Developer
    Lead Developer

    Tried the hook method today, it didn’t work along with the filterable element method.

    I think being able to filter it is a better idea, as it will allow for custom markup. Remind me when beta.2 comes out and I’ll write up some code for you 🙂

    #621725
    George

    Ok Tom, thanks. Meanwhile I used this addon to add if shortcodes and used one of those conditionals in the hero header. It worked fine.

    [if is_single=no]Content here.[/if]

    #622150
    Tom
    Lead Developer
    Lead Developer

    Cool! Is that a plugin?

    #627643
    George

    Yeah, sorry, it’s this one. Hasn’t been updated for 3 years though, you think it’s safe?

    #627700
    Tom
    Lead Developer
    Lead Developer

    Looks pretty simple code-wise. However, I wouldn’t stop searching for a more recent one as time goes on.

    #627741
    George

    Ok thanks for having a look! Would the new beta 3 header hooks be able to also address the issue?

    #627991
    Tom
    Lead Developer
    Lead Developer

    Hooks themselves accept PHP, but the Page Heros won’t.

    #628274
    George

    You can hook content inside the page hero now though, right?

    #628469
    Tom
    Lead Developer
    Lead Developer

    No, there are no hooks inside the Page Hero.

    However, the entire element is filterable, so you can add elements into it/change the elements that are displayed by default.

    #1236701
    George

    Sorry to come back to this after almost two years, lol! In what way can a header element be filtered?

    #1237068
    David
    Staff
    Customer Support

    The entire element is filterable – Tom provides the basics here for filtering the hero html within:

    https://generatepress.com/forums/topic/inside-hero-hook/#post-927610

    #1237694
    George

    Ok, I see.

    I am trying to enter a shortcode like this:
    https://gist.github.com/quantumleap33/ef77205bddc55e74be7822c7cecd2e8e

    but the shortcode is not displayed.

    I have also tried that:
    https://gist.github.com/quantumleap33/0c4112d1b8070550583295e6e454a7ef

    but the shortcode displays as text.

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