# Insert php code before get\_header

**URL:** https://forum.pinegrow.com/t/insert-php-code-before-get-header/6943
**Category:** Beginners
**Created:** [September 9, 2022, 9:32pm UTC](https://forum.pinegrow.com/t/insert-php-code-before-get-header/6943 "2022-09-09T21:32:00Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![fogseller](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/fogseller/32/4260_2.png) [@fogseller](https://forum.pinegrow.com/u/fogseller)
#### Post date: [September 9, 2022, 9:32pm UTC](https://forum.pinegrow.com/t/insert-php-code-before-get-header/6943/1 "2022-09-09T21:32:00Z")

</div>

hello, i need help 🙂

i have custom query and if there is no posts shown page is redirected to another page like this

\<?php else : wp\_redirect( get\_permalink ( 717 ) ); die; ?\>

but, for that to work i need to insert

\<?php ob\_start(); ?\>

before

\<?php get\_header(); ?\>

question is: is there any way to insert it within pinegrow so i don’t need to copypaste it every time after page is exported/overwritten?

thank you very much

---

<div class="post-metadata">

### Author: ![fogseller](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/fogseller/32/4260_2.png) [@fogseller](https://forum.pinegrow.com/u/fogseller)
#### Post date: [September 10, 2022, 10:36am UTC](https://forum.pinegrow.com/t/insert-php-code-before-get-header/6943/2 "2022-09-10T10:36:16Z")

</div>

@matjaz @RobM@Emmanuel is this even possible? To put something before \<?php get\_header(); ?\>

---

<div class="post-metadata">

### Author: ![matjaz](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/matjaz/32/5_2.png) [@matjaz](https://forum.pinegrow.com/u/matjaz)
#### Post date: [September 10, 2022, 1:43pm UTC](https://forum.pinegrow.com/t/insert-php-code-before-get-header/6943/3 "2022-09-10T13:43:27Z")

</div>

@fogseller it might be possible to add it at the start of the header. Would that help?

Alternative would be adding the call into a WP action handler (not sure which action that would be) in inc/custom.php so that you won’t have to manually edit exported files.

---

<div class="post-metadata">

### Author: ![Emmanuel](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/emmanuel/32/6294_2.png) [@Emmanuel](https://forum.pinegrow.com/u/Emmanuel)
#### Post date: [September 10, 2022, 2:18pm UTC](https://forum.pinegrow.com/t/insert-php-code-before-get-header/6943/4 "2022-09-10T14:18:50Z")

</div>

Something like this maybe :

- [add\_action() | Function | WordPress Developer Resources](https://developer.wordpress.org/reference/functions/add_action/)
- [init | Hook | WordPress Developer Resources](https://developer.wordpress.org/reference/hooks/init/)
- [php - What is add\_action( 'init - Stack Overflow](https://stackoverflow.com/questions/21201266/what-is-add-action-init)

---

<div class="post-metadata">

### Author: ![fogseller](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/fogseller/32/4260_2.png) [@fogseller](https://forum.pinegrow.com/u/fogseller)
#### Post date: [September 11, 2022, 7:09am UTC](https://forum.pinegrow.com/t/insert-php-code-before-get-header/6943/5 "2022-09-11T07:09:19Z")

</div>

hey, thank you. i will try all options and write what worked 👍
