- This topic has 6 replies, 2 voices, and was last updated 4 years, 5 months ago by
Leo.
-
AuthorPosts
-
October 19, 2021 at 11:33 am #1968884
Hilton
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
October 19, 2021 at 11:36 am #1968890Hilton
ps. I don’t want to use any plugin. Thanks 😉
October 19, 2021 at 11:43 am #1968900Leo
StaffCustomer SupportHi 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_PageA general WordPress question like this would be good for a general WordPress forum like Stack:
https://wordpress.stackexchange.com/October 19, 2021 at 12:26 pm #1968941Hilton
Hi,
I did that following this article https://getflywheel.com/layout/show-different-sidebars-posts-pages-wordpress-how-to/
Thanks
October 19, 2021 at 1:05 pm #1968968Leo
StaffCustomer SupportSounds 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.
October 19, 2021 at 1:20 pm #1968988Hilton
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.
October 19, 2021 at 1:43 pm #1969010Leo
StaffCustomer SupportSounds 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_PageYou 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!
-
AuthorPosts
- You must be logged in to reply to this topic.