0

I moved get_sidebar(); from header.php to footer.php but it simply does not appear is being placed after the last post in the page body instead of after the footer. There are no errors displayed. What do I need to do to get this working?

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 -->
                <footer>
                    <div id="footframe">
                        <small class="blk"><?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>
                        <small class="blk">This page &copy; Copyright 2009 Michael Horvath. Last modified: <?php echo date("F d Y H:i:s", getlastmod()) ?>.</small>
                    </div>
<?php wp_footer(); //Crucial footer hook! ?>
                </footer>
                <!-- END FOOTERS -->
            </div>
            <!-- END MIDDLE PANE -->
            <!-- START SIDEBAR -->
            <div id="leftframe">
                <div id="sidebarframetop">
                    <div id="sidebar_widget">
<?php get_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>

The rendered HTML:

                </main>
                <!-- END PAGE CONTENTS -->
                <!-- START FOOTERS -->
                <footer>
                    <div id="footframe">
                        <small class="blk">Proudly powered by WordPress. Theme: isometricland by Michael Horvath based on <a href="http://underscores.me/" rel="designer">Underscores.me</a> GPLv2 or later.</small>
                        <small class="blk">This page &copy; Copyright 2009 Michael Horvath. Last modified: February 06 2020 17:03:12.</small>
                    </div>
<script type="text/javascript">(function(a,d){if(a._nsl===d){a._nsl=[];var c=function(){if(a.jQuery===d)setTimeout(c,33);else{for(var b=0;b<a._nsl.length;b++)a._nsl[b].call(a,a.jQuery);a._nsl={push:function(b){b.call(a,a.jQuery)}}}};c()}})(window);</script><script type='text/javascript' src='https://isometricland.net/blog/wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/scripts/shCore.js?ver=3.0.9b' id='syntaxhighlighter-core-js'></script>
<script type='text/javascript' src='https://isometricland.net/blog/wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/scripts/shBrushCss.js?ver=3.0.9b' id='syntaxhighlighter-brush-css-js'></script>
<script type='text/javascript'>
    (function(){
        var corecss = document.createElement('link');
        var themecss = document.createElement('link');
        var corecssurl = "https://isometricland.net/blog/wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/styles/shCore.css?ver=3.0.9b";
        if ( corecss.setAttribute ) {
                corecss.setAttribute( "rel", "stylesheet" );
                corecss.setAttribute( "type", "text/css" );
                corecss.setAttribute( "href", corecssurl );
        } else {
                corecss.rel = "stylesheet";
                corecss.href = corecssurl;
        }
        document.head.appendChild( corecss );
        var themecssurl = "https://isometricland.net/blog/wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/styles/shThemeFadeToGrey.css?ver=3.0.9b";
        if ( themecss.setAttribute ) {
                themecss.setAttribute( "rel", "stylesheet" );
                themecss.setAttribute( "type", "text/css" );
                themecss.setAttribute( "href", themecssurl );
        } else {
                themecss.rel = "stylesheet";
                themecss.href = themecssurl;
        }
        document.head.appendChild( themecss );
    })();
    SyntaxHighlighter.config.strings.expandSource = '+ expand source';
    SyntaxHighlighter.config.strings.help = '?';
    SyntaxHighlighter.config.strings.alert = 'SyntaxHighlighter\n\n';
    SyntaxHighlighter.config.strings.noBrush = 'Can\'t find brush for: ';
    SyntaxHighlighter.config.strings.brushNotHtmlScript = 'Brush wasn\'t configured for html-script option: ';
    SyntaxHighlighter.defaults['class-name'] = 'syntax';
    SyntaxHighlighter.defaults['pad-line-numbers'] = true;
    SyntaxHighlighter.all();

    // Infinite scroll support
    if ( typeof( jQuery ) !== 'undefined' ) {
        jQuery( function( $ ) {
            $( document.body ).on( 'post-load', function() {
                SyntaxHighlighter.highlight();
            } );
        } );
    }
</script>
<script type='text/javascript' src='https://isometricland.net/blog/wp-content/themes/isometricland/js/navigation.js?ver=20151215' id='isometricland-navigation-js'></script>
<script type='text/javascript' src='https://isometricland.net/blog/wp-content/themes/isometricland/js/skip-link-focus-fix.js?ver=20151215' id='isometricland-skip-link-focus-fix-js'></script>
<script type='text/javascript' src='https://isometricland.net/blog/wp-includes/js/wp-embed.min.js?ver=5.7.1' id='wp-embed-js'></script>
<script type="text/javascript">(function (undefined) {var _targetWindow ="prefer-popup";
window.NSLPopup = function (url, title, w, h) {
    var userAgent = navigator.userAgent,
        mobile = function () {
            return /\b(iPhone|iP[ao]d)/.test(userAgent) ||
                /\b(iP[ao]d)/.test(userAgent) ||
                /Android/i.test(userAgent) ||
                /Mobile/i.test(userAgent);
        },
        screenX = window.screenX !== undefined ? window.screenX : window.screenLeft,
        screenY = window.screenY !== undefined ? window.screenY : window.screenTop,
        outerWidth = window.outerWidth !== undefined ? window.outerWidth : document.documentElement.clientWidth,
        outerHeight = window.outerHeight !== undefined ? window.outerHeight : document.documentElement.clientHeight - 22,
        targetWidth = mobile() ? null : w,
        targetHeight = mobile() ? null : h,
        V = screenX < 0 ? window.screen.width + screenX : screenX,
        left = parseInt(V + (outerWidth - targetWidth) / 2, 10),
        right = parseInt(screenY + (outerHeight - targetHeight) / 2.5, 10),
        features = [];
    if (targetWidth !== null) {
        features.push('width=' + targetWidth);
    }
    if (targetHeight !== null) {
        features.push('height=' + targetHeight);
    }
    features.push('left=' + left);
    features.push('top=' + right);
    features.push('scrollbars=1');

    var newWindow = window.open(url, title, features.join(','));

    if (window.focus) {
        newWindow.focus();
    }

    return newWindow;
};

var isWebView = null;

function checkWebView() {
    if (isWebView === null) {
        function _detectOS(ua) {
            if (/Android/.test(ua)) {
                return "Android";
            } else if (/iPhone|iPad|iPod/.test(ua)) {
                return "iOS";
            } else if (/Windows/.test(ua)) {
                return "Windows";
            } else if (/Mac OS X/.test(ua)) {
                return "Mac";
            } else if (/CrOS/.test(ua)) {
                return "Chrome OS";
            } else if (/Firefox/.test(ua)) {
                return "Firefox OS";
            }
            return "";
        }

        function _detectBrowser(ua) {
            var android = /Android/.test(ua);

            if (/CriOS/.test(ua)) {
                return "Chrome for iOS";
            } else if (/Edge/.test(ua)) {
                return "Edge";
            } else if (android && /Silk\//.test(ua)) {
                return "Silk";
            } else if (/Chrome/.test(ua)) {
                return "Chrome";
            } else if (/Firefox/.test(ua)) {
                return "Firefox";
            } else if (android) {
                return "AOSP";
            } else if (/MSIE|Trident/.test(ua)) {
                return "IE";
            } else if (/Safari\//.test(ua)) {
                return "Safari";
            } else if (/AppleWebKit/.test(ua)) {
                return "WebKit";
            }
            return "";
        }

        function _detectBrowserVersion(ua, browser) {
            if (browser === "Chrome for iOS") {
                return _getVersion(ua, "CriOS/");
            } else if (browser === "Edge") {
                return _getVersion(ua, "Edge/");
            } else if (browser === "Chrome") {
                return _getVersion(ua, "Chrome/");
            } else if (browser === "Firefox") {
                return _getVersion(ua, "Firefox/");
            } else if (browser === "Silk") {
                return _getVersion(ua, "Silk/");
            } else if (browser === "AOSP") {
                return _getVersion(ua, "Version/");
            } else if (browser === "IE") {
                return /IEMobile/.test(ua) ? _getVersion(ua, "IEMobile/") :
                    /MSIE/.test(ua) ? _getVersion(ua, "MSIE ")
                        :
                        _getVersion(ua, "rv:");
            } else if (browser === "Safari") {
                return _getVersion(ua, "Version/");
            } else if (browser === "WebKit") {
                return _getVersion(ua, "WebKit/");
            }
            return "0.0.0";
        }

        function _getVersion(ua, token) {
            try {
                return _normalizeSemverString(ua.split(token)[1].trim().split(/[^\w\.]/)[0]);
            } catch (o_O) {
            }
            return "0.0.0";
        }

        function _normalizeSemverString(version) {
            var ary = version.split(/[\._]/);
            return (parseInt(ary[0], 10) || 0) + "." +
                (parseInt(ary[1], 10) || 0) + "." +
                (parseInt(ary[2], 10) || 0);
        }

        function _isWebView(ua, os, browser, version, options) {
            switch (os + browser) {
                case "iOSSafari":
                    return false;
                case "iOSWebKit":
                    return _isWebView_iOS(options);
                case "AndroidAOSP":
                    return false;
                case "AndroidChrome":
                    return parseFloat(version) >= 42 ? /; wv/.test(ua) : /\d{2}\.0\.0/.test(version) ? true : _isWebView_Android(options);
            }
            return false;
        }

        function _isWebView_iOS(options) {
            var document = (window["document"] || {});

            if ("WEB_VIEW" in options) {
                return options["WEB_VIEW"];
            }
            return !("fullscreenEnabled" in document || "webkitFullscreenEnabled" in document || false);
        }

        function _isWebView_Android(options) {
            if ("WEB_VIEW" in options) {
                return options["WEB_VIEW"];
            }
            return !("requestFileSystem" in window || "webkitRequestFileSystem" in window || false);
        }

        var options = {};
        var nav = window.navigator || {};
        var ua = nav.userAgent || "";
        var os = _detectOS(ua);
        var browser = _detectBrowser(ua);
        var browserVersion = _detectBrowserVersion(ua, browser);

        isWebView = _isWebView(ua, os, browser, browserVersion, options);
    }

    return isWebView;
}

function isAllowedWebViewForUserAgent() {
    var nav = window.navigator || {};
    var ua = nav.userAgent || "";
    if (/Instagram/.test(ua)) {
        /*Instagram WebView*/
        return true;
    } else if (/FBAV/.test(ua) || /FBAN/.test(ua)) {
        /*Facebook WebView*/
        return true;
    }

    return false;
}

window._nsl.push(function ($) {

    window.nslRedirect = function (url) {
        $('<div style="position:fixed;z-index:1000000;left:0;top:0;width:100%;height:100%;"></div>').appendTo('body');
        window.location = url;
    };

    var targetWindow = _targetWindow || 'prefer-popup',
        lastPopup = false;

    $(document.body).on('click', 'a[data-plugin="nsl"][data-action="connect"],a[data-plugin="nsl"][data-action="link"]', function (e) {
        if (lastPopup && !lastPopup.closed) {
            e.preventDefault();
            lastPopup.focus();
        } else {

            var $target = $(this),
                href = $target.attr('href'),
                success = false;
            if (href.indexOf('?') !== -1) {
                href += '&';
            } else {
                href += '?';
            }
            var redirectTo = $target.data('redirect');
            if (redirectTo === 'current') {
                href += 'redirect=' + encodeURIComponent(window.location.href) + '&';
            } else if (redirectTo && redirectTo !== '') {
                href += 'redirect=' + encodeURIComponent(redirectTo) + '&';
            }

            if (targetWindow !== 'prefer-same-window' && checkWebView()) {
                targetWindow = 'prefer-same-window';
            }

            if (targetWindow === 'prefer-popup') {

                lastPopup = NSLPopup(href + 'display=popup', 'nsl-social-connect', $target.data('popupwidth'), $target.data('popupheight'));
                if (lastPopup) {
                    success = true;
                    e.preventDefault();
                }
            } else if (targetWindow === 'prefer-new-tab') {
                var newTab = window.open(href + 'display=popup', '_blank');
                if (newTab) {
                    if (window.focus) {
                        newTab.focus();
                    }
                    success = true;
                    e.preventDefault();
                }
            }

            if (!success) {
                window.location = href;
                e.preventDefault();
            }
        }
    });

    var googleLoginButton = $('a[data-plugin="nsl"][data-provider="google"]');
    if (googleLoginButton.length && checkWebView() && !isAllowedWebViewForUserAgent()) {
        googleLoginButton.remove();
    }
});})();</script>               </footer>
                <!-- END FOOTERS -->
            </div>
            <!-- END MIDDLE PANE -->
            <!-- START SIDEBAR -->
            <div id="leftframe">
                <div id="sidebarframetop">
                    <div id="sidebar_widget">
                    </div>
                </div>
                <div id="sidebarframebot">
                    <div id="file_paypal">
                    </div>
                    <div id="file_search">
                    </div>
                    <div id="file_social">
<div class="social" title="DeviantArt"  ><a href="https://posfan12.deviantart.com/"             target="_blank"><img class="nomagnify" style="margin:0px;" src="https://isometricland.net/images/icon_deviantart.png"   alt="DeviantArt"    /></a></div>
<div class="social" title="Facebook"    ><a href="https://www.facebook.com/michael.horvath.35"          target="_blank"><img class="nomagnify" style="margin:0px;" src="https://isometricland.net/images/icon_facebook.png" alt="Facebook"      /></a></div>
<div class="social" title="Flickr"  ><a href="https://www.flickr.com/photos/108839565@N04/"         target="_blank"><img class="nomagnify" style="margin:0px;" src="https://isometricland.net/images/icon_flickr.png"   alt="Flickr"        /></a></div>
<div class="social" title="GitHub"  ><a href="https://github.com/mjhorvath"                 target="_blank"><img class="nomagnify" style="margin:0px;" src="https://isometricland.net/images/icon_github.png"   alt="GitHub"        /></a></div>
<br/>
<div class="social" title="Goodreads"   ><a href="https://www.goodreads.com/user/show/67971043-michael-horvath" target="_blank"><img class="nomagnify" style="margin:0px;" src="https://isometricland.net/images/icon_goodreads.png"    alt="Goodreads"     /></a></div>
<div class="social" title="LinkedIn"    ><a href="https://www.linkedin.com/in/michael-horvath-45547a116/"   target="_blank"><img class="nomagnify" style="margin:0px;" src="https://isometricland.net/images/icon_linkedin.png" alt="LinkedIn"      /></a></div>
<div class="social" title="Spotify" ><a href="https://open.spotify.com/user/f1703yjwz5hxcrndycvbjfwbl"  target="_blank"><img class="nomagnify" style="margin:0px;" src="https://isometricland.net/images/icon_spotify.png"  alt="Spotify"       /></a></div>
<div class="social" title="Wikipedia"   ><a href="https://en.wikipedia.org/wiki/User:Datumizer"         target="_blank"><img class="nomagnify" style="margin:0px;" src="https://isometricland.net/images/icon_wikipedia.png"    alt="Wikipedia"     /></a></div>
                    </div>
                    <div id="file_norml">
                    </div>
                </div>
            </div>
            <!-- END SIDEBAR -->
        </div>
    </body>
</html>
10
  • Share you code please
    – anton
    Commented May 1, 2021 at 13:45
  • It is being taken out of the context I specify and placed after the last post instead.
    – posfan12
    Commented May 1, 2021 at 14:07
  • What is the second block of code? That looks correct? Commented May 1, 2021 at 14:29
  • So where is a problem if you have an output, if you dont specify sidebar name for get_sidebar it will output default sidebar, which you pasted here)
    – anton
    Commented May 1, 2021 at 14:32
  • 1
    what you posted as 'rendered html' is clearly not generated from what you posted as code in footer.php - the html tags and CSS does not match. what html code is rendered in the footer?
    – Michael
    Commented May 1, 2021 at 19:58

2 Answers 2

1

You need to read the documentation, get_sidebar():

Includes the sidebar template for a theme or if a name is specified then a specialised sidebar will be included.

Its purpose is to load sidebar.php. It does not output widgets. To output widgets you need to use dynamic_sidebar():

<?php dynamic_sidebar( 'sidebar-1' ); ?>

That will output the widgets added to that widget area. This is clearly outlined in the documentation.

4
  • Thanks. Why is dynamic_sidebar() required in the footer but not in the header?
    – posfan12
    Commented May 4, 2021 at 2:25
  • It’s not required anywhere. Commented May 4, 2021 at 3:25
  • Excuse me let me rephrase that. Why is get_sidebar() by itself sufficient in the header but not in the footer? (That is the default behavior in the theme I'm using.)
    – posfan12
    Commented May 5, 2021 at 2:52
  • Also, the sidebar is now being generated TWICE. Once in the correct location, but also still in the footer.
    – posfan12
    Commented May 5, 2021 at 2:56
0

If you want it in the footer, just put it in the footer.

            </main>
            <!-- END PAGE CONTENTS -->
            <!-- START FOOTERS -->
            <footer>
              <div id="footframe">
              </div>                    
              <!-- START SIDEBAR -->
              <div id="leftframe">
               <div id="sidebarframetop">
                <div id="sidebar_widget">
                  <?php get_sidebar(); ?>
                 </div>
                </div>
               </div>
              <!-- END SIDEBAR -->
             <?php wp_footer(); //Crucial footer hook! ?>
            </footer>
            <!-- END FOOTERS -->
1
  • I don't want it in the actual footer. I just want it toward the end of the HTML so that I don't have to explicitly set the TABINDEXes of my nav bar elements.
    – posfan12
    Commented May 1, 2021 at 20:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.