• if you edit the main plugin file i123_per_page_widgets.php line 196

    Change the function i123_widgets_custom_fields_add() as below and the widgets chooser will show up in your custom post types as well.

    [ Moderator Note: Please post code or markup snippets between backticks or use the code button. ]

    function i123_widgets_custom_fields_add() {
        i123_widgets_admin_init();
        add_meta_box( 'i123_widgets_custom_fields', __('Per Page Widgets', 'i123_widgets'), 'i123_widgets_custom_fields_controllbox', 'post', 'side', 'high' );
        add_meta_box( 'i123_widgets_custom_fields', __('Per Page Widgets', 'i123_widgets'), 'i123_widgets_custom_fields_controllbox', 'page', 'side', 'high' );
    	$args=array(
    		'public' => true,
    		'_builtin' => false
    	);
    	$operator = "and"; //'and or 'or'
    	$output = "names"; //names or objects - names is default
    	$post_types = get_post_types($args,$output,$operator);
    	foreach($post_types as $post_type) {
    		add_meta_box( 'i123_widgets_custom_fields', __('Per Page Widgets', 'i123_widgets'), 'i123_widgets_custom_fields_controllbox', $post_type, 'side', 'high' );
    	}
    }

    https://www.ads-software.com/extend/plugins/per-page-widgets/

Viewing 1 replies (of 1 total)
  • This is the right idea, but there is a better approach.

    Instead of editing the plugin file, use the WordPress action hook add_meta_boxes in your functions.php file or custom plugin. This way the boxes get added and you won’t run into upgrade issues on the plugin.

    Here’s the adapted implementation:

    function my_custom_meta_boxes( $post_type, $post ) {
    	$args = array(
    		'public' => true,
    		'_builtin' => false
    	);
    	$operator = "and"; //'and or 'or'
    	$output = "names"; //names or objects - names is default
    	$post_types = get_post_types($args,$output,$operator);
    
    	foreach($post_types as $post_type) {
    		add_meta_box( 'i123_widgets_custom_fields', __('Per Page Widgets', 'i123_widgets'), 'i123_widgets_custom_fields_controllbox', $post_type, 'side', 'high' );
    	}
    }
    
    add_action( 'add_meta_boxes', 'my_custom_meta_boxes', 10, 2 );
Viewing 1 replies (of 1 total)
  • The topic ‘modification to add per page widgets to custom post types’ is closed to new replies.