• Resolved akachan

    (@akachan)


    Hi.

    i have this code in my function.php:

    add_filter( 'sidebars_widgets', function( $sidebars_widgets ) {
    
        $sidebar_index = 'sidebar-1';
    
        if( isset( $sidebars_widgets[$sidebar_index] ) )
        {
              shuffle( $sidebars_widgets[$sidebar_index] );
    	  $sidebars_widgets[$sidebar_index] = array_slice( $sidebars_widgets[$sidebar_index], 0, 8 );
    
        }
        return $sidebars_widgets;
    }, PHP_INT_MAX );

    Working perfect. I see 8 randomly widgets in one widget area. Problem is a see 8 randomly widgets in my administration too. It is possible to make an exception in this code for admin area. I will see all widget there.

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • try working with is_admin(), i.e. try to change the one line to:

    if( !is_admin() && isset( $sidebars_widgets[$sidebar_index] ) )

    https://codex.www.ads-software.com/Function_Reference/is_admin

    (not tested)

    Thread Starter akachan

    (@akachan)

    I use is_front_page() and seems to be working.

    add_filter( 'sidebars_widgets', function( $sidebars_widgets ) {
    
        $sidebar_index = 'sidebar-1';
    
        if( is_front_page() && isset( $sidebars_widgets[$sidebar_index] ) )
        {
              shuffle( $sidebars_widgets[$sidebar_index] );
    	  $sidebars_widgets[$sidebar_index] = array_slice( $sidebars_widgets[$sidebar_index], 0, 7 );
    
        }
        return $sidebars_widgets;
    }, PHP_INT_MAX );

    Thank you to kick me in right way.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Exception in function.php’ is closed to new replies.