• Resolved cra1g

    (@cra1g)


    I’m wanting a plugin that will change the author’s name in the byline. For example, I like to have guest bloggers write every now and then, but I don’t want to have to make an entire account just so their name shows up in the byline. Is there a way that I can create a post myself, but manually type in the author’s name in the byline?

Viewing 9 replies - 1 through 9 (of 9 total)
  • The code below will create a plugin called ‘Substitute Author’ when copied to a file wp-content/plugins/substitute_author/substitute_author.php.

    It reads a Custom Field named sa_author from a post and substitutes the value of the field for the Author name as shown by the_author(). Just add that Custom Field to your posts with the name you want substituted.

    <?php
    /*
    Plugin Name: Substitute Author
    Version: 0.1
    Description: Substitutes an Author name from a Custom Field
    Use the custom field sa_author with a value of the substitute Author's name.
    Author: Mac McDonald
    */
    ?>
    <?php
    /* Version check */
    global $wp_version;
    $exit_msg='Substitute Author requires WordPress 2.8 or newer.  <a href="https://codex.www.ads-software.com/Upgrading_WordPress">Please update!</a>';
    if (version_compare($wp_version,"2.5","<")) {
       exit ($exit_msg);
    }
    
    function sa_substitute_author_filter ($author_name) {
       global $post;
       $custom_author = get_post_meta($post->ID,'sa_author',true);
       if ($custom_author) $author_name = $custom_author;
       return $author_name;
    }
    add_filter('the_author', 'sa_substitute_author_filter');
    ?>
    Thread Starter cra1g

    (@cra1g)

    Can you better explain that to me? Do I create the substitute_author.php file and then paste that code into it?

    And I got lost when you started explaining how to use it. lol

    Yes, you do create substitute_author.php and paste the code into it.

    Then, create a folder as wp-content/plugins/substitute_author and save the php file into it.

    When you edit (or create) a post that you want to have a substitute author, do the following:

    1. Scroll down to the Custom Fields section.
    2. Click ‘Enter new’
    3. In the Name field, type: sa_author
    4. In the Value field, type the name of the author
    5. Click ‘Add Custom Field’
    6. Click ‘Update Post’ (or ‘Publish’)

    Now, when you view the post, you should see the substitute name as the author.

    By the way vtxyzzy, your code should work fine since at least WP 2.2 and even some versions back I believe ;).

    Could be, but I can’t test it on those versions.

    Thread Starter cra1g

    (@cra1g)

    Ok, I did all the steps you mentioned and it didn’t work. It still shows my name in the Byline. I double checked and made sure I did everything correctly and I did.

    Did you activate the plugin? Sorry, I didn’t put that in the instructions.

    Thread Starter cra1g

    (@cra1g)

    Haha, I can’t believe I didn’t think of that. It’s working now. My only complaint is that when you click on the substituted author’s name in the byline, it takes you to the actual author’s page. Not a huge deal really.

    Thanks!

    Glad it works. Now, please use the dropdown at top right to mark this topic ‘Resolved’.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Need a Specific Plugin’ is closed to new replies.