WordPress Include ‘print_f’ in WP_Customize_Control array

I have the following problem: I want to add print_f in an array in wordpress.

printf( __('Option to share on %s', 'themename'), 'name')

However, the following code does not work properly for me. Instead of the actual result, it throws out “30”
.

$wp_customize->add_control(
                        new WP_Customize_Control(
                                $wp_customize,
                                'display-name'
                                array(
                                        'label' => printf( __('Option to share on %s', 'theme-name'), 'name'),
                                        'section' => 'share',
                                        'settings' => 'display-name',
                                        'type' => 'checkbox',
                                        'description' => 'Just a Description.'
                                        'active_callback' => 'share_callback',
                                )
                        )
                );

Hope someone can help me…

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

As documented (always read the docs), printf() returns:

…the length of the outputted string.

That’s why you’re getting 30.

If you’re adding a value to an array or a string you need to use a function that returns a value. Not one that prints. printf() prints the value and returns the length of the printed value. To return a formatted string, you need to use sprintf():

'label' => sprintf( __('Option to share on %s', 'theme-name'), 'name'),

See here for more on the difference between returning and printing/echoing.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x