Support

Account

Home Forums Backend Issues (wp-admin) Adding ACF field to Widgets.php NOT inside of a widget

Helping

Adding ACF field to Widgets.php NOT inside of a widget

  • I’d like to use ACF to create new dynamic sidebars (field name ‘create_sidebar’) that I can then add widgets to. If I place ‘create_sidebar’ on Options page, it works fine, but I’d really like to move it to the widgets.php page so user doesn’t need to create sidebar on one page, then go to widgets.php to fill newly created sidebar.

    I can’t seem to get the location property to work.

    function acf_location_rules_types( $choices ) {
        $choices['Page']['admin'] = 'Admin Page';
        return $choices;
    }
    add_filter('acf/location/rule_types', 'acf_location_rules_types');
    
    function acf_location_rules_values_admin( $choices ) {
    	return 'widgets';
    }
    add_filter('acf/location/rule_values/admin', 'acf_location_rules_values_admin');
    
    function acf_location_rules_match_admin( $match, $rule, $options ) {
    
    	    $current_screen = get_current_screen();
    	    $selected_screen = (int) $rule['value'];
    	
    	    if($rule['operator'] == "==") {
    	    	$match = ($current_screen->id == $selected_screen);
    	    }
    	    elseif($rule['operator'] == "!=") {
    	    	$match = ( $current_screen->id != $selected_screen );
    	    }
    	
    	    return $match;
    }
    
    add_filter('acf/location/rule_match/admin', 'acf_location_rules_match_admin', 10, 3);
  • It is not possible to directly add ACF field groups to the widget page. Basically it is not possible to add ACF field groups to any of the WP admin pages. Honestly, I don’t know if it is even possible to alter the widgets page or any WP settings page at all without making changes to WP core. I just did a quick search on this and came up empty.

    If there were any hooks that let these pages be modified I’m sure that ACF would already be doing it.

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

You must be logged in to reply to this topic.