Archived topic
Custom template - Content not formating - shortcode not working
10 replies · Started by Paul on April 23, 2022
I have created a custom template for a specific page because I need a different header.
I can select the template fine for that specific page but when I load the page, the content is not being rendered out properly and the shortcode I have in the content box on that page is not working.
The page works fine along with the formatting when I just use the default template.
I have included all the page code and examples in the private info box.
Thanks in advance!
Code used for new templates
--------------------------------------------------------
page-map.php
---------------------------------
<div >
<main >
</main>
</div>
<div class="clear"> </div>
<?php
get_footer();
--------------------------------------------------------
content-map.php
---------------------------------
<div class="navigation post-navigation">
<div class="breadcrumbs">
<?php /*if ( function_exists('yoast_breadcrumb') ) { yoast_breadcrumb( '<p id="breadcrumbs">','</p>' );} */?>
</div>
</div>
<article id="post-" >
<div class="inside-article">
<header >
</header>
<div class="entry-content">
'<div class="page-links">' . __( 'Pages:', 'generatepress' ),
'after' => '</div>',
)
);
?>
</div>
</div>
</article>
--------------------------------------------------------
header-map.php
--------------------------------------------------------
<html >
<meta charset="">
window.nitroAds=window.nitroAds||{createAd:function(){window.nitroAds.queue.push(["createAd",arguments])},addUserToken:function(){window.nitroAds.queue.push(["addUserToken",arguments])},queue:[]};
<body >
<div >
<div >
<?php
/**
* generate_inside_container hook.
*
* @since 0.1
*/
do_action( 'generate_inside_container' );
Relpying as I forgot to tick notifications :)
Hi there,
lets go back a bit - what's different about the header that required a new page template ?
As it may be easier just to hook in your changes to the theme template.
Hi David
So the header on the new template will not have a banner ad at the top to make the map easier to use. So in the n ew template I would simply omit that code.
Cheers
Paul
Ok, to save you editing templates you can use a Hook Element ( or a Block Element - type hook ):
https://docs.generatepress.com/article/hooks-element-overview/
You can then add your code to the Hook, and select which Hook to attach it to.
See here for a rough guide to the Hooks available:
https://docs.generatepress.com/article/hooks-visual-guide/
Maybe use the generate_after_header hook for placing stuff between the site header and the content.
Then set the Display Rules locations to define where it would be displayed.
Hi David
That would work. However, it's not ideal. Say for whatever reason we needed to change the theme, we also have pages that serve specific purposes like embedded javascript calculators and tools that sometimes require a completely different layout.
I think in this case I'll just omit the code with an if page id =.
However, I would like to know why the above code does not work?
OK - if you right click > inspect the broken page theres a bunch of errors related to jQuery - it looks like your custom page template isn't enqueuing the jQuery library.
Hi David
Weird, I did check the console for errors. Is there a reason that would be happening considering it's an exact copy of a Generatepress template? Does something need to be set specifically to enqueue scripts for custom layout templates in the theme?
Cheers
Paul
GeneratePress doesn't load jQuery ( unless you enable the Sticky Navigation ).
So on the working pages there must be a function or plugin that is enqueuing that script.
I see Easy ticker and Search Filter 'plugins' are using jQuery - will you be adding either of those to your custom template? As they should enqueue the script for you.
Hi David
Thanks for clarifying that. I think the previous theme we used before switching last week enqueued scripts which is why it worked fine using this method so that explains the difference.
Now I know what it is, I'll figure something out and get it working :)
Thanks for all the help!
Yeah a lot of themes just auto enqueue whether they need it or not lol - GP tries its best to just add what is needed.
Glad to be of some help!