I'm currently working on a plugin. I have to render a lot of html on a specific page. I've placed that piece of code in the plugin it's core file, like so:
add_filter('the_content', 'overwrite_content');
function overwrite_content($content) {
if(is_page('Signup')){
require_once(plugin_dir_path(__FILE__).'/views/signup.php');
$content = '';
}
else if(is_page('Bedankt')){
require_once(plugin_dir_path(__FILE__).'/views/thanks.php');
$content = '';
}
return $content;
}
It all works fine, but for some reason all <head>
elements are being placed underneath my custom html within the <body>
think of <meta, <title> etc
.
Does anyone know how I fix this? I'd rather skip creating a shortcode, since the html is just simply too much.
<head>
tag from inside a shortcode or fromthe_content
filter, and you shouldn't be outputting HTML directly to the browser inside that filter, you need to return it instead. Otherwise that output happens immediatley, not at the location the filtered HTML is used<head>
. But in what way returning do you mean? Likereturn '<div>test</div>';
?require_once
you're outputting directly to the browser any templates/tags the same wayprint
orecho
does. That way the output of those files is immediately sent when they're executedmeta
/title
tags etc to the page, the content filter or a shortcode are far too late, it needs to happen much earlier while WP outputs the header