WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] printf weirdness with comment_author_link (3 posts)

  1. fouriertransform
    Member
    Posted 7 years ago #

    Hi all,

    printf is driving me insane. Whenever is use it, the string being called up appears at the front of the returned output no matter where it appears in the formatting string. This could be worked around were it not for the fact that I'm using Polyglot to translate between two languages, so I need the string location to be different in each language - it always appears at the front though.

    If in my comments template I write:

    printf('Here is what %s said:', comment_author_link());

    I get the output:
    AuthorHere is what said:

    Which is no good.

    printf obviously works, because the following:

    printf('Here is what %s said:', 'Geoff');

    gives me, as expected,
    Here is what Geoff said:

    So comment_author_link is doing weird stuff and pushing itself to the front of the queue. Why? And how do I make it stop? I can't see anything in comment_functions.php to make it do that, but then I no php expert.

    Any help appreciated.

  2. Kafkaesqui

    Posted 7 years ago #

    PHP 101: Do not pass functions through other functions which echo or print their held value.

    Instead of comment_author_link(), which displays the url of a commenter, try:

    printf('Here is what %s said:', get_comment_author_link());

    (get_comment_author_link() does exactly what comment_author_link() does, but returns rather than echoes the value it holds).

  3. fouriertransform
    Member
    Posted 7 years ago #

    That is beautiful - and lightning fast! I have a lot to learn...

    Thank you so much :)

Topic Closed

This topic has been closed to new replies.

About this Topic