Archived topic
Replace the widget of a specific page
6 replies · Started by Hilton on October 19, 2021
Hi, I registered a new sidebar using the function below in functions.php:
function arphabet_widgets_init() {
register_sidebar( array(
'name' => 'Recipes Filter',
'id' => 'recipes_filter',
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<div class="widget-title">',
'after_title' => '</div>',
) );
}
add_action( 'widgets_init', 'arphabet_widgets_init' );
So far so good, the sidebar appears in the specific area of Wordpress. But now I would like to know how I can put this sidebar specifically on a page that has the url http://www.mysite.com/my-page
Thanks
ps. I don't want to use any plugin. Thanks ;)
Hi there,
I'd say that using a plugin like this is the easiest solution:
https://en-ca.wordpress.org/plugins/content-aware-sidebars/
If not you will likely need to use an if statement and WP conditional tags:
https://codex.wordpress.org/Conditional_Tags#A_PAGE_Page
A general WordPress question like this would be good for a general WordPress forum like Stack:
https://wordpress.stackexchange.com/
Hi,
I did that following this article https://getflywheel.com/layout/show-different-sidebars-posts-pages-wordpress-how-to/
Thanks
Sounds good.
I would say that the plugin solution I recommended would work just as well without any custom coding - most of our users find the plugin very helpful and it should have minimal impact on your site performance if that's your concern.
If you need help modifying the existing solution then you can try commenting on the article you found.
I think certain occasional needs don't need plugins. If I want this for one page only, why will I install a plugin for this if I can solve it with a few lines of code. I'm always very concerned when it comes to code, less is more.
Sounds good!
Then I believe the PHP if statement plus the WP conditional tag is what you need:
https://www.php.net/manual/en/control-structures.if.php
https://codex.wordpress.org/Conditional_Tags#A_PAGE_Page
You can always check with the author of the article/custom solution to see if he can help with the code tweaking as well.
Good luck!