yourprefix_register_theme_options_metabox

Hook in and register a metabox to handle a theme options page.

Description

yourprefix_register_theme_options_metabox(); 

Usage

  1. if ( !function_exists( 'yourprefix_register_theme_options_metabox' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'cmb2/example-functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = yourprefix_register_theme_options_metabox(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/example-functions.php  
  1. function yourprefix_register_theme_options_metabox() { 
  2.  
  3. $option_key = 'yourprefix_theme_options'; 
  4.  
  5. /** 
  6. * Metabox for an options page. Will not be added automatically, but needs to be called with 
  7. * the `cmb2_metabox_form` helper function. See https://github.com/WebDevStudios/CMB2/wiki for more info. 
  8. */ 
  9. $cmb_options = new_cmb2_box( array( 
  10. 'id' => $option_key . 'page',  
  11. 'title' => esc_html__( 'Theme Options Metabox', cmb2 ),  
  12. 'hookup' => false, // Do not need the normal user/post hookup 
  13. 'show_on' => array( 
  14. // These are important, don't remove 
  15. 'key' => 'options-page',  
  16. 'value' => array( $option_key ) 
  17. ),  
  18. ) ); 
  19.  
  20. /** 
  21. * Options fields ids only need 
  22. * to be unique within this option group. 
  23. * Prefix is not needed. 
  24. */ 
  25. $cmb_options->add_field( array( 
  26. 'name' => esc_html__( 'Site Background Color', cmb2 ),  
  27. 'desc' => esc_html__( 'field description (optional)', cmb2 ),  
  28. 'id' => 'bg_color',  
  29. 'type' => 'colorpicker',  
  30. 'default' => '#ffffff',  
  31. ) ); 
  32.