Support

Account

Home Forums General Issues Using ACF to display different widgets on pages

Solving

Using ACF to display different widgets on pages

  • I have setup a custom field for displaying widgets based on different pages and posts.

    How can I code this?

    Here is the code for the sidebar

    <?php /* Widgetized sidebar */
    if ( !function_exists(‘dynamic_sidebar’) || !dynamic_sidebar(‘sidebar-9’) ) : ?><?php endif; ?>

    Here is the code for the custom field

    <?php the_field(‘previous_page’); ?>

  • I have setup a custom field with a select and the different short names of the different sidebars. I would like to have the sidebar reflect the widgets based on the sidebar selected.

  • 
    <?php 
      $sidebar = get_field('sidebar'); // or whatever your field is named
      if (is_active_sidebar($sidebar)) {
        dynamic_sidebar($sidebar);
      }
    ?>
    

    you should take a look at this https://codex.wordpress.org/Function_Reference/dynamic_sidebar. There are many ways to code the sidebar and you may need additional html code. I’d suggest looking at some of the 20XX themes to see how they do it.

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Using ACF to display different widgets on pages’ is closed to new replies.