简体   繁体   中英

Using an alternative sidebar when creating a Wordpress theme

I'm trying to figure out how to load an alternative sidebar in a Wordpress theme I'm creating (I'm a novice, by the way). A very old answer on stackoverflow suggests creating a new sidebar and calling it something like sidebar_alt.php and altering the code as follows:

<?php get_sidebar('alt'); ?>

But that doesn't work for me, it just keeps loading the original sidebar. I read a different answer that said you have to register the alternative sidebar in the functions.php file. Do any of you very nice, smart and helpful people out there know if this is true? If so, what code would I have to add? Or is there another alternative (that doesn't include plugins)?

Many thanks in advance.

https://codex.wordpress.org/Function_Reference/get_sidebar

You have created sidebar file with name "sidebar_alt.php" which is wrong you should create it like "sidebar-{name}.php" eg. "sidebar-alt.php". eg. "sidebar-alt.php".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM