1

I'm looking a way tho change the the_author(); function in the loop, I have post meta data with the name of the user who posted.

I need to do this:

  • If the user is registered, show the_author();, but if isn't show the data from the post meta.

Since the_author(), function doesn't have a callback function I'm a little lost, maybe making a function?

The idea is replace the_author() in my theme.

1 Answer 1

1

There is no need to change the the_author() function itself. A simple conditional tag will do the trick. Example:

<?php

/*** on your functions.php file ***/
function ifRegistered() {
    if(is_user_logged_in()) {
        the_author();
    } else {
        echo get_the_post_meta($post->ID, 'your_post_meta_key', true);
        // or anything else, of course
    }
}

/*** on the template you want to use the function  **/

// your HTML markup ...

    ifRegistered();

// more possible HTML ...

?>

Hope that helps!

EDIT: Updated the function.

2
  • Looking for registered user not current logged in user, but i have the idea, is possible to make it like a function to replace the the_author(), for my custom function on every template file? Thanks. Commented Dec 15, 2011 at 16:07
  • 1
    If the user is logged in, it means he/she is registered. Edited my answer with the function.
    – cr0z3r
    Commented Dec 15, 2011 at 16:11

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.