• I tried loading the theme I built onto a live site of mine that I will not be renewing. Everything looked fine except the sidebar and footer did not load on single post pages that use single.php. I also used All In One WP Migration to pull my second site down to local dev and I had the same problem there.

    I have my theme installed on my new site and there are no problems at all. I installed the plugin Show Current Template and there is something off…

    1. On my live new site using my theme with no errors, hovering over the Show Current Template admin bar link you can see every template being loaded including template-parts.
    2. In my local dev for the site mentioned in #1 directly above, the sidebar and footer show but hovering over the Show Current TEmplate link does not list ANY templates at all.
    3. In the local dev that have the content I pulled down with All in One, I see 2 different things for the Show Current Template link:
    – 3a) no templates listed for pages that DO have a footer and sidebar
    – 3b) template files listed for single.php that do NOT have a sidebar or footer loaded and those files are not listed???

    Very confusing. I took some screenshots and loaded them into my media library of one of my sites since I don’t know how else to load an image: https://everyguitarchord.com/wp-content/uploads/2021/01/problem-with-single.php_.png

    NOTE: That link is not the page I need help with!

    Any thoughts on why this would happen? I suspect the issue is either:
    1. My free theme OceanWP with all their styles and scripts
    2. Elementor page builder
    3. All the info that was pulled down with All In One Migration, and therefore maybe fully populated databases.

    But for the local dev that has no issues, I forget how I did it but I pulled in dummy content from a .XML link and I guess I used the plugin WordPress Importer plugin. So that populated my databases. Why does my live site or local dev with live data data cause this problem? I don’t even know how to start looking for the issue.

Viewing 7 replies - 1 through 7 (of 7 total)
  • if possible post the theme code for single.php. Did you remember to add get_header() and get_footer() to the top and bottom of the theme?

    • This reply was modified 3 years, 10 months ago by mrtom414.
    Thread Starter Jim

    (@kernix)

    wp_head is in the header, wp_footer is in the footer, and I have get_header( ‘post’ ); and get_footer(); is the main template files including single.php. As you can tell I have more than one header file, but only one footer file at this time.

    I built the theme using Underscores and the only files I didn’t touch were was woocommerce.css, menutoggle.js though I think I deleted navigation.js since it didn’t work. I have my own mobile menu script. The other files that are ‘suspect’ are in the inc folder: custom-header.php, customizer.php, template-functions.php, template-tags.php, and woocommerce.php.

    template-tags.php though I removed the meta functions since I didn’t know where the PHP variables (%1$s, %2$s) were getting the fields. I got the meta for my posts via a simpler way that I could understand.

    But inc/template-functions.php has 2 functions and one of them is checking for ! is_singular. I deleted my singular.php file since it wasn’t loading anywhere but have since put it back. Here is that function:

    function tower_body_classes( $classes ) {
    	// Adds a class of hfeed to non-singular pages.
    	if ( ! is_singular() ) {
    		$classes[] = 'hfeed';
    	}
    
    	// Adds a class of no-sidebar when there is no sidebar present.
    	if ( ! is_active_sidebar( 'sidebar-1' ) ) {
    		$classes[] = 'no-sidebar';
    	}
    
    	return $classes;
    }
    add_filter( 'body_class', 'tower_body_classes' );

    Here is single.php:

    get_header( 'post' );
    ?>
    
    	<main id="primary" class="site-main">
    		<div class="container sidebar-page">
    			<article class="blog-page">
    				<header>
    					<h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
    				</header>
    					<?php
    					while ( have_posts() ) :
    						the_post();
    
    						get_template_part( 'template-parts/content', get_post_format() );
    						
    						// comments go here
    
    					endwhile; // End of the loop.
    					?>
    
    				<!-- custom widget area -->
    				<?php if ( ! is_active_sidebar( 'custom-widget' ) ) {
    				return;
    				}
    				?>
    
    				<!-- <div class="custom-widgets" id="secondary" class="widget-area custom-widget-area" role="complementary"> -->
    				<div class="custom-widgets custom-widget-area" role="complementary">
    
    					<?php dynamic_sidebar( 'custom-widget' ); ?>
    
    				</div>
    			</article>
    			<aside class="blog-sidebar">
    				<?php get_sidebar(); ?>
    			</aside>
    		</div><!-- .container .sidebar-page-->
    	</main><!-- #main -->
    
    <?php
    get_footer();
    • This reply was modified 3 years, 10 months ago by Jim.
    Thread Starter Jim

    (@kernix)

    Now it’s my live site. footer.php and sidebar.php are not loading on single blog posts. This is devastating. I don’t understand why there is no problem at all on my local dev version of my site. Do you think it could be something with my host Siteground? I’ll never get any kind of clients with these kinds of problems.

    Here is a link to one of my blog posts: https://kernixwebdesign.com/website/33-online-review-business-listing-sites/

    Show Current Template plugin does not show footer or sidebar but it also doesn’t show template-parts/content.php which is what I use for single posts.

    Thread Starter Jim

    (@kernix)

    I cut out the template-tags.php functions for the author and meta because it used the goofy %1$s thing which I couldn’t figure out. So I created my own template parts and call them inside of content.php. Is that a potential problem? Calling template parts into a template part when they are all in the same folder? Should I go back to the template-tags.php functions or create another template-parts folder inside of template parts or the inc folder? Any help on this would be appreciated. It’s getting late so I’m calling it a night for now.

    The weird thing is though that there is no problem on local dev. It’s only on my live sites hosted on Siteground or on the ALL IN ONE WP Migration that is in another WP install and that is from Siteground as well.

    Moderator bcworkz

    (@bcworkz)

    Hi kernix,
    It sounds like you really did need a good break from all this. I hope you got a good night’s sleep. If you’re reading this before then, stop right now and go to bed! This can wait ??

    I think you might be encountering a difference in PHP versions. If your template includes involve partial paths, that’s a strong indication, as some versions require full paths (by using get_stylesheet_directory() or similar). Also double check that the file permissions are correct on the siteground server.

    And yes, your template parts can load other template parts. From the same folder or anywhere else in the file system. Just don’t load the same part that loads its own part or you’ll get an infinite recursion and run out of memory.

    Thread Starter Jim

    (@kernix)

    @bcworkz I figured it out – I created a widget area in single.php so that I could add a recent posts section on each single post page. I forgot to use if ( is_active_sidebar( ‘custom-widget’ ) ) before using dynamic_sidebar( ‘custom-widget’ ) – I couldn’t sleep and it came to me around 3:30 that it must be the custom widget area in singe.php. I took it out and the footer and sidebar were back.

    And I guess it is the difference in PHP versions why it worked in local dev since I am using XAMPP and XAMPP doesn’t automatically update.

    Thread Starter Jim

    (@kernix)

    No, not the PHP version – my local dev without the problem has a recent posts widget in that custom widget area. I’m sure if I removed the sidebar and footer would disappear without the is_Active_sidebar statement.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘My theme will not load footer.php or sidebar.php…’ is closed to new replies.