I have an extra copy of the sidebar content appearing after the last post and before the footer in the output HTML. So I have one on the side in the correct position, and one at the end of the page. Any idea on how to get rid of the second one?
functions.php
/**
* Register widget area.
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function isometricland_widgets_init() {
register_sidebar( array(
'name' => esc_html__( 'Sidebar', 'isometricland' ),
'id' => 'sidebar-1',
'description' => esc_html__( 'Add widgets here.', 'isometricland' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'isometricland_widgets_init' );
footer.php
<?php
global $path_root, $page_title, $path_img, $path_ssi, $path_css, $path_jav;
include_once($path_ssi . 'plugin-paypal.php');
include_once($path_ssi . 'plugin-sitesearch.php');
include_once($path_ssi . 'plugin-socialicons.php');
include_once($path_ssi . 'plugin-norml.php');
?>
</main>
<!-- END PAGE CONTENTS -->
<!-- START FOOTERS -->
<div id="footframe">
<footer>
<div><small><?php printf( __( 'Proudly powered by %s.', 'isometricland' ), 'WordPress' ); ?> <?php printf( __( 'Theme: %1$s by Michael Horvath based on %2$s GPLv2 or later.', 'isometricland' ), 'isometricland', '<a href="http://underscores.me/" rel="designer">Underscores.me</a>' ); ?></small></div>
<div><small>>>><a href="https://isometricland.net/pages/sitemap.php">sitemap</a><<<</small></div>
</footer>
<?php wp_footer(); //Crucial footer hook! ?>
</div>
<!-- END FOOTERS -->
</div>
<!-- END MIDDLE PANE -->
<!-- START SIDEBAR -->
<div id="leftframe">
<div id="sidebarframetop">
<div id="sidebar_widget">
<?php dynamic_sidebar( 'sidebar-1' ); ?>
</div>
</div>
<div id="sidebarframebot">
<div id="file_paypal">
<?php //echo writePaypalDonate(); ?>
</div>
<div id="file_search">
<?php //echo writeSiteSearchForm(); ?>
</div>
<div id="file_social">
<?php echo writeSocialIcons(); ?>
</div>
<div id="file_norml">
<?php //echo writeNormlLogo(); ?>
</div>
</div>
</div>
<!-- END SIDEBAR -->
</div>
</body>
</html>
header.php
<?php
global $path_root, $page_title, $path_img, $path_ssi, $path_css, $path_jav;
include_once($path_ssi . 'plugin-analyticstracking.php');
include_once($path_ssi . 'plugin-verytopbar.php');
?>
<!DOCTYPE HTML>
<html <?php language_attributes(); ?>>
<head>
<?php echo writeAnalyticsTracking(); ?>
<meta charset="<?php bloginfo('charset'); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="profile" href="http://gmpg.org/xfn/11">
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>">
<link rel="alternate" href="<?php bloginfo('rss2_url'); ?>" title="<?php bloginfo('name'); ?> RSS Feed" type="application/rss+xml" />
<link type="text/css" rel="stylesheet" href="<?php echo $path_css; ?>style-main.css"/>
<link type="text/css" rel="stylesheet" href="<?php echo $path_css; ?>style-dropdown.css"/>
<link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"/>
<link rel="icon" type="image/png" href="<?php echo $path_root; ?>favicon.png"/>
<script src="<?php echo $path_jav; ?>dropdown.js"></script>
<script src="<?php echo $path_jav; ?>cubesnake.js"></script>
<?php wp_head(); ?>
</head>
<body onload="">
<div id="seed_pane"><img id="seed_image" src="https://isometricland.net/svg/seed_of_life_monochrome.svg"/></div>
<div id="snake_pane"></div>
<div id="outerframe">
<!-- START MIDDLE PANE -->
<div id="middleframe">
<!-- START FAUX WP ADMIN BAR -->
<div id="verytopbar">
<nav role="navigation">
<?php echo writeVeryTopBar(); ?>
</nav>
</div>
<!-- END FAUX WP ADMIN BAR -->
<!-- START PAGE CONTENTS -->
<main>
sidebar.php
<?php
/**
* The sidebar containing the main widget area
*
* @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
*
* @package Isometricland
*/
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
return;
}
?>
<aside id="secondary" class="widget-area">
<?php dynamic_sidebar( 'sidebar-1' ); ?>
</aside><!-- #secondary -->
index.php
<?php
$path_root = "../../../../";
$path_img = "../../../../images/";
$path_css = "../../../../css/";
$path_jav = "../../../../java/";
$path_ssi = "../ssi/";
$page_title = "Blog";
include_once($path_ssi . 'directory.php');
include_once($path_ssi . 'getpageinfo.php');
?>
<?php
/**
* The main template file
*
* This is the most generic template file in a WordPress theme
* and one of the two required files for a theme (the other being style.css).
* It is used to display a page when nothing more specific matches a query.
* E.g., it puts together the home page when no home.php file exists.
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/
*
* @package Isometricland
*/
get_header();
?>
<div id="primary" class="content-area">
<main id="main" class="site-main">
<?php
if ( have_posts() ) :
if ( is_home() && ! is_front_page() ) :
?>
<header>
<h1 class="page-title screen-reader-text"><?php single_post_title(); ?></h1>
</header>
<?php
endif;
/* Start the Loop */
while ( have_posts() ) :
the_post();
/*
* Include the Post-Type-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Type name) and that will be used instead.
*/
get_template_part( 'template-parts/content', get_post_type() );
endwhile;
the_posts_navigation();
else :
get_template_part( 'template-parts/content', 'none' );
endif;
?>
</main><!-- #main -->
</div><!-- #primary -->
<?php
get_sidebar();
get_footer();
single.php
<?php
$path_root = "../../../../";
$path_img = "../../../../images/";
$path_css = "../../../../css/";
$path_jav = "../../../../java/";
$path_ssi = "../ssi/";
$page_title = "Blog";
include_once($path_ssi . 'directory.php');
include_once($path_ssi . 'getpageinfo.php');
?>
<?php
/**
* The template for displaying all single posts
*
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post
*
* @package Isometricland
*/
get_header();
?>
<div id="primary" class="content-area">
<main id="main" class="site-main">
<?php
while ( have_posts() ) :
the_post();
get_template_part( 'template-parts/content', get_post_type() );
the_post_navigation();
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
endwhile; // End of the loop.
?>
</main><!-- #main -->
</div><!-- #primary -->
<?php
get_sidebar();
get_footer();
Screenshot of two copies of sidebar.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
IF you look at all the templates included in your question, the reason becomes obvious: You’re outputting the sidebar twice.
In index.php you use get_sidebar(), which loads sidebar.php. In that template you’re outputting the widgets:
<aside id="secondary" class="widget-area">
<?php dynamic_sidebar( 'sidebar-1' ); ?>
</aside><!-- #secondary -->
You’re also using get_footer(), which loads footer.php. In that template you’re also outputting the widgets:
<div id="sidebar_widget">
<?php dynamic_sidebar( 'sidebar-1' ); ?>
</div>
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0
