Skip to content

Add New Section

Henner R Setyono edited this page Mar 12, 2020 · 5 revisions
add_filter( 'custy_sections', function( $sections ) {} );

Example

We want to add a new section where we can toggle on and off various features:

add_filter( 'custy_sections', function( $sections ) {

  $sections[ 'features' ] = [
    'title' => __( 'Features' ),
    'container' => [ 'priority' => 10 ],
    'options' => [
      
      'has_back_to_top' => [
        'label' => __( 'Has Back to Top?' ),
        'type' => 'ct-switch',
      ],

      'has_fixed_header' => [
        'label' => __( 'Has Fixed Header?' ),
        'type' => 'ct-switch',
      ],

      'has_blog_sidebar' => [
        'label' => __( 'Has Blog Sidebar?' ),
        'type' => 'ct-switch',
      ],
    
    ]
  ];

  return $sections;
} );

Then, define the default values of those new options:

add_filter( 'custy_default_values', function( $defaults ) {

  $defaults = wp_parse_args( [
    
    'has_back_to_top' => 'yes',
    'has_fixed_header' => 'no',
    'has_blog_sidebar' => 'yes',

  ], $defaults );

  return $defaults;
} );

Done!, Check out the Customizer and you will see a new section called "Features"

Frontend Implementation

if( Custy::get_mod('has_back_to_top') == 'yes' ) {
  // output the back to top
}

Clone this wiki locally