WordPress.org

Support

Support » Plugins and Hacks » Hacks » Custom WordPress author names

Custom WordPress author names

  • Hi All,

    I am migrating my school’s Online Newspaper from Joomla to WordPress, and I am trying to modify the theme (Twenty Fourteen), so that it uses a metadata key value as the display name for a post (since most of the content creators have had their posts submitted to the old site using an editor as a proxy, so their names are stored as ‘author aliases’).
    It should be as simple as:

    if (author_id = 0) {
        $author_name = $meta['alias'];
    }

    My awesome php simplification
    But where should this be implemented within the vast expanse of wordpress code.

    I would also greatly appreciate being shown how to configure all of the other author related perks (list author posts, these authors have contributed etc.)

    I would show you the site in situ, but unfortunately it is running on my local dev machine. Not that seeing it would help at all.

    any help at all would be greatly appreciated!

    — Wilky

Viewing 6 replies - 1 through 6 (of 6 total)
  • esmi

    @esmi

    Forum Moderator

    I am trying to modify the theme (Twenty Fourteen)

    Do not edit the Twenty Fourteen theme. It is the current default WordPress theme and having access to an original, unedited, copy of the theme is vital in many situations. First create a child theme for your changes.

    Right now, I am more concerned about getting the site going.

    Whilst I will use a child theme, I am more concerned about my problem.

    – Wilky

    Moderator bcworkz

    @bcworkz

    I think you are better off doing a one time DB upgrade that updates the official post author for all posts with author aliases. Then there is no need to chase after every place author data appears and substitute the alias.

    No themes or child themes are involved. Either create a single use plugin for the task or do it from within phpMyAdmin.

    I see what you are trying to do. I would use the wp_insert_post_data function to do this. (note this is just an untested proof of concept, will probably need some tweaking.)

    function change_author( $data , $postarr )
    {
        $post_id = $postarr['ID'];
    
        $author_name = get_post_meta( $post_id, 'alias', true);
    
        if ( $data['post_author'] == 0 ){
            $data['post_author'] = $author_name;
        }
        return $data;
    }
    
    add_filter('wp_insert_post_data' , 'change_author' , '99', 2);

    I suggest you to create a child theme and apply code to that in admin section.

    if (author_id = 0) {
    $author_name = $meta[‘alias’];
    }

    or you can update the current database’s user table to specify your requirements.

    I wrote a plugin to solve the problem and it did not require creating a child theme.

    I cleaned up the code, and will submit it to the plugin directory either tonight or tomorrow.

    I will post it here when it is uploaded. 😉

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom WordPress author names’ is closed to new replies.
Skip to toolbar