[Support request] Replace the widget of a specific page

Home Forums Support [Support request] Replace the widget of a specific page

Home Forums Support Replace the widget of a specific page

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #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

    #1968890
    Hilton

    ps. I don’t want to use any plugin. Thanks 😉

    #1968900
    Leo
    Staff
    Customer Support

    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/

    #1968941
    Hilton
    #1968968
    Leo
    Staff
    Customer Support

    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.

    #1968988
    Hilton

    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.

    #1969010
    Leo
    Staff
    Customer Support

    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!

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.