kkhan00
Forum Replies Created
-
Forum: Themes and Templates
In reply to: how can I put the contents of get_header() in a variable?Okay, I JUST figured this out! woohoo!
So the reason why it was outputting the header twice is because I was using
ob_end_flush
which actually outputs whatever was inside the buffer. Changing that toob_end_clean
will get rid of the contents inside the buffer without outputting it to the screen.Anyhow, I guess this can be useful to someone in the future. Also, if anyone else knows a better way of doing this PLEASE share it!
So, in the end, to get the contents of
get_header()
or any other void functions within WordPress without having it displayed on the screen, use the following code:ob_start(); // starts the internal buffer get_header(); // or get_footer, etc $content = get_ob_contents(); // ob_end_clean();
Forum: Themes and Templates
In reply to: how can I put the contents of get_header() in a variable?sorry, I may have spoken too soon.
The code I tried above actually does copy the
get_header();
content onto the variable, however, it shows the content twice on the page when I try to get the variable content displayed.Forum: Themes and Templates
In reply to: how can I put the contents of get_header() in a variable?no it doesn’t.
The code above doesn’t even create a separate output stream I think. By calling
get_header();
afterob_start();
, it just displays the content on the page as if you were to callget_header();
normally.Maybe I’m doing this wrong?
Forum: Themes and Templates
In reply to: how can I put the contents of get_header() in a variable?Can you elaborate a little? I tried this but all it did was again just display the contents of get_header();
ob_start(); get_header(); $wordpress_header = ob_get_contents(); ob_end_flush();