Make Theme Options Native to Theme Customizer

Step 1: Register the setting in the customizer

Add this to your wptuts_theme_customizer() function, which will register a new “Pagination” section, as well as a “Pagination Style” setting:

/* Section: Pagination */
$wp_customize->add_section( 'themeslug_pagination', array(
    'title' => __( 'Pagination', 'themeslug' ),
) );
$wp_customize->add_setting( 'pagination_style', array(
    'default' => 'next-previous-links',
) );
$wp_customize->add_control( 'pagination_style', array(
    'label'   => __( 'Pagination Style', 'themeslug' ),
    'section' => 'themeslug_pagination',
    'type'    => 'radio',
    'choices' => array(
        'next-previous-links' => __( 'Next/Previous Links', 'themeslug' ),
        'numbered'            => __( 'Numbered', 'themeslug' ),
    ),
) );

Step 2: Modify the pagination function to work with the customizer setting

Modify your my_theme_navigation() function like this:

BEFORE:
if( get_option( $shortname . '_next_prev_or_paginate' ) == 'Next/Previous Links' ) :

AFTER:
if ( 'next-previous-links' == get_theme_mod( 'pagination_style' ) ) :

Note that because theme mods are specific to the currently active theme, you don’t need to prefix them with {$themename}_, which would be redundant.

Here is your original code, with my modifications added:

Leave a Comment