I'm in the single.php and now need to use the_content() instead of just $post->post_content; for youtube embeds etc.–

in other projects the_content() and apply_filters("the_content", ...) does what it should do, but not in this single.php ... Twentyseventeen theme with the same plugins works great with the_content(); so it must be my theme.

After hours of researching and fiddling around I found out that I did this pretty early in the code:

$GLOBALS = array(
    "active_menu" => "...",
    "something_else" => true

// don't ask me why I did this, I was a even more a noob back then; 
// it's been working fine so far; no time to refactor.. u know the excuses–

// of course I just do it like this now:
$GLOBALS["active_menu"] = "...";
$GLOBALS["something_else"] = true;

When I wanted to see what might be so crucial in the "original" $GLOBALS, the browser loaded like it went to Oblivion and back again. So much stuff inside this var.

So here's the question

  1. Why did an overwritten $GLOBALS which is sooo big, kill the filter?

Template tags like the_content() and the_title() are dependent on the global $post variable ($GLOBALS['post']).

See the source code for get_post(), which get_the_title(), for example, uses to get the current post so it can get its title:

function get_post( $post = null, $output = OBJECT, $filter = 'raw' ) {
    if ( empty( $post ) && isset( $GLOBALS['post'] ) )
        $post = $GLOBALS['post'];

WordPress is heavily dependent on global variables. See this codex article on the global variables. You really shouldn't be overwriting it entirely or you'll break more than just template tags. I'm surprised you made it this far, honestly.

  • That's what surprised me the most by that revelation aswell! That's why I am asking this question :D – Thanks for the article and the nice answer :) – kater louis Dec 19 '17 at 17:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.