Return a numerical function value in Customizer controls

I’m trying to add some controls to the WordPress Customizer feature, but I’m having trouble pulling the numerical value from the control to use in the theme. The section appears in the Customizer tab, and I can change the input, but the controls have no effect on the theme.

I’ve looked up tutorials that use the get_theme_mod and inline styles to set attributes for divs, but I haven’t been able to figure out exactly how to make the control id just return the input of a custom numerical value.

‘title’ => esc_html__( ‘Grid Style’, ‘news-portal-child’ ),
‘panel’ => ‘news_portal_grid_settings_panel’,
‘priority’ => 25,

‘default’ => ‘6’,
‘sanitize_callback’ => ‘sanitize_key’,
$wp_customize->add_control(new WP_Customize_Control ($wp_customize,
‘type’ => ‘text’,
‘section’ => ‘news_portal_grid_section’,
‘settings’ => ‘np_posts_per_page’,
‘priority’ => 2,
‘label’ => __( ‘Grid Posts’ ),
‘description’ => __( ‘This sets the number of posts to display. This must be numeric.’ ),
‘validate’ => ‘numeric’,
‘default’ => ‘5’,
‘input_attrs’ => array(
‘min’ => 0,
‘max’ => 50,
‘step’ => 1,

)) );

I know there should be a function/action hook here somewhere, but the WordPress API is a little vague on how exactly to implement this. I need the number output of np_post_num() to return as a simple integer or string that can then be declared in $option_pg_number= _________.

function np_post_num(){
echo get_theme_mod(‘np_posts_per_page’, ‘5’);
add_action (‘wp_head’, ‘np_post_num’);

Read more here:: Return a numerical function value in Customizer controls

Leave a Reply

Your email address will not be published. Required fields are marked *