0

So I'm getting the following error Warning: printf(): Too few arguments in /lib/helpers.php on line 34

So line 34 is 'class' => []

// Define the read more url
function read_more_url() {

    // Grab the posts link and title
    echo '<a href="' . esc_url(get_the_permalink()) . '" title="' . the_title_attribute(['echo' => false]) . '">';

    printf(
        // Filters text content and strips out disallowed HTML
        wp_kses(
            __('Read more <span class="u-screen-reader-text">about %s</span>', 'Sema'),
            [
                'span' => [
                    'class' => []
                ]
            ]
        )
    );
}

Could someone tell me what I might be doing wrong? The echo is working correctly.

1 Answer 1

1

Your printf statement awaits additional string argument which would be substituted instead of %s:

    printf(
        // Filters text content and strips out disallowed HTML
        wp_kses(
            __('Read more <span class="u-screen-reader-text">about %s</span>', 'Sema'),
            [
                'span' => [
                    'class' => []
                ]
            ]
        ), "some subject"
    );

This example would produce the following output:

Read more <span class="u-screen-reader-text">about some subject</span>

5
  • Ivan thanks so much! Is there a reason that my %s might not be returning the_title()?
    – DevSem
    Jun 28, 2020 at 2:12
  • It isn't supposed to return a title. It is supposed to be substituted by some string given as second printf parameter (use the_title() as second parameter for your case). The reason to use this technique is because you don't know how this phrase would be looking in some other language and where the post title should be appeared (at the beginning of the phrase, at the end of the phrase, etc). Jun 28, 2020 at 2:17
  • Ahh, that makes much more sense! Would you tackle the print out any differently? I'm still in the learning phases and printf made the most sense to me - Now when I pass get_title() as the second param, of course like you mentioned, the output is Hello World!Read more about.
    – DevSem
    Jun 28, 2020 at 2:20
  • 1
    Try the_title('', '', false) instead. Or better use get_the_title(). Jun 28, 2020 at 2:25
  • Works like a charm! Appreciate all the help!
    – DevSem
    Jun 28, 2020 at 2:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.