Site logo

Archived topic

Write PHP inside custom page headers?

17 replies · Started by George on July 11, 2018

Viewing posts 1–15 of 18

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?

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 :)

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

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 :)

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]

Cool! Is that a plugin?

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

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

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

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

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

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.

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

This archived topic is closed to new replies.