I'm developing a theme for WordPress, for hobby and for studying a little PHP, JavaScript etc. and I'm having a little problem.
I'm working with the controller concept where all logic will be processed and then sent to a view. To make it clear how my theme is structured I'll go over my directory structure:
Thecontroller-single.php
willcontrolthedatathatwillberenderedinsingle.php
initIdefinetheController_Single
classthatwillmanagethecontentsofthepage/postsandthenIcallthenecessarypartstoanddisplaythecontents:<?phprequire_once__DIR__.'/../security.php';classController_Single{publicfunction__construct(){add_filter('get_single_content',array($this,'get_single_content'));}publicfunctionget_single_content(){$single_content=newStdClass();$single_content->title=get_the_title();//TítulodoPost$single_content->author=get_the_author();//AutordoPost$single_content->date=get_the_date();//Datadepublicação$single_content->content=get_the_content();//ConteúdodoPostreturn$single_content;}}newController_Single();
Andinmysingle.phpIperformthecallofcontent:
<?phpget_header();the_post();$single_post=apply_filters('get_single_content',false);?><headerclass="glory-header">
<div class="glory-header-title">
<h2><?php echo $single_post->title ?></h2>
<p>Publicado por: <span><?php echo $single_post->author ?></span> em <?php echo $single_post->date ?></p>
</div>
<div class="glory-header-overlay"></div>
</header>
<div class="glory-page-body">
<?php echo $single_post->content ?>
</div>
<?php get_footer() ?>
The problem is that since I'm using get_the_content();
in controller.php instead of the_content();
WordPress does not do auto embeds which is a problem for me since I go work with shortcodes, galleries etc.
However, if I use the_content();
the content of the post will appear soon after the opening of the <body>
tag and, consequently, above all page elements (header, nav etc).
I've read about the possibility of circumventing this, however, I could not find a functional solution to the problem.