change author url without wordpress plugin

wp user want to use other url for admin user. You can easily change using wordpress hook. you can change author url in wordpress without wordpress plugin. using code you can do this. wordpress developer can use this code.

change author url without wordpress plugin

There is default username in wordpress. admin is default username in wordpress but many times user want to use other wordpress user url for admin user. You can easily do this by using following wordpress hook.

You just need to place following code in functions.php file which is your theme folder.

add_action('init', 'change_wordpress_author_url');
function change_wordpress_author_url() {
global $wp_rewrite;
$author_slug = 'new_author_url';
$wp_rewrite->author_base = $author_slug;
}

You need to choose your author url. Just replace the “new_author_url” word and put in functions.php file.

change author url without wordpress plugin
how to change the author url in wordpress without wordpress plugin

Display the authors in dropdown menu using wp_dropdown_users – Hook/Filter

One of my client faced issue with Autor drop down which is in Admin section.

Display the authors in dropdown menu using hooks.

While creating the New post there was problem with the Author field. There are hundreds of irrelevant selections (users) and it’s difficult to select the right one.

WordPress is by default showing all the users in author drop down. I don’t want to show the other users in author drop down.

Display the authors in a dropdown menu
Hook/Filter – In wordpress Admin -Add new Post section -Display the authors in a dropdown menu using wp_dropdown_users One of my client faced issue with Autor drop down which is in Admin section. Display the authors in a dropdown menu using hooks

I searched for wp_dropdown_users hook or filter. But I did not found any proper solution.

Following articles are found helpful to me.
http://wordpress.org/support/topic/filter-for-post-quick-edit-author-drop-down
http://codex.wordpress.org/Function_Reference/wp_dropdown_users

Using that code I modified the code and I am able to fix the issue. You can put following code in to functions.php file.

 /*
 * Hook for showing Admin and Author in Add new Post - Admin section dropdown menu
 */
function wpapi_override_wp_dropdown_users($output) {
    global $post, $user_ID;
    //get the Admin-role users IDs
    $admins = getUsersWithRole('admin');
    //get the author-role users IDs
    $authors = getUsersWithRole('author');
    //merge the array
    $result = array_merge($admins, $authors);

    //array converted into comma seprated string
    $authorsall = implode(",", $result);

    // return if this isn't the theme author override dropdown
    if (!preg_match('/post_author_override/', $output))
        return $output;

    // return if we've already replaced the list (end recursion)
    if (preg_match('/post_author_override_replaced/', $output))
        return $output;

    // replacement call to wp_dropdown_users
    $output = wp_dropdown_users(array(
        'echo' => 0,
        'name' => 'post_author_override_replaced',
        'selected' => empty($post->ID) ? $user_ID : $post->post_author,
        'include_selected' => true,
        'include' => $authorsall
    ));

    // put the original name back
    $output = preg_replace('/post_author_override_replaced/', 'post_author_override', $output);

    return $output;
}

add_filter('wp_dropdown_users', 'wpapi_override_wp_dropdown_users');

/*
 * Find User IDs by Role
 */

function getUsersWithRole($role) {
    $wp_user_search = new WP_User_Search($usersearch, $userspage, $role);
    return $wp_user_search->get_results();
}

Using above code, you can load multiple role users in author drop down.

how to show author information on each wordpress post

show author information on each wordpress post is really good habit in wordpress post. So reader will know information writer who is writing the article. Many people like this information and they really read the information about author.

how to show author information on each wordpress post

how to show author information on each wordpress post
how to show author information on each wordpress post

For showing the author information you need put following code in the functions.php file show after your post content the author information will displayed to reader.


function get_author_bio($content=''){
global $post;

$post_author_name=get_the_author_meta("display_name");
$post_author_description=get_the_author_meta("description");
$html="</pre>
<div id="about_author" class="clearfix">\n";
$html.="<img class="avatar" src="http://www.gravatar.com/avatar.php?gravatar_id=&quot;.md5(get_the_author_email()). &quot;&default=&quot;.urlencode($GLOBALS[" alt="PG" width="80" height="80" />\n";
$html.="
<div class="author_text">\n";
$html.="
<h4>Author: ".$post_author_name."</h4>
\n";
$html.= $post_author_description."\n";
$html.="</div>
</div>
<pre>
\n";
$html.="</pre>
<div class="clear"></div>
<pre>
\n";
$content .= $html;

return $content;
}

add_filter('the_content', 'get_author_bio');

Just put the above code in functions.php file. You dont need to do code in single.php file.