The get_the_author_msn() WordPress PHP function retrieves the MSN address of the author of the current post.
Usage
get_the_author_msn();
Example:
Input: echo get_the_author_msn();
Output: [email protected]
Parameters
- None
More information
See WordPress Developer Resources: get_the_author_msn
Examples
Display the author’s MSN address in a post
Display the MSN address of the author within a post or page.
function display_author_msn() {
$msn_address = get_the_author_msn();
echo 'MSN Address: <strong>' . $msn_address . '</strong>';
}
add_action('the_content', 'display_author_msn');
Add author’s MSN address to post metadata
Add the MSN address of the author to the post’s metadata.
function add_author_msn_to_metadata($post_id) {
$msn_address = get_the_author_msn();
update_post_meta($post_id, 'author_msn_address', $msn_address);
}
add_action('save_post', 'add_author_msn_to_metadata');
Show author’s MSN address in author box
Create an author box that includes the author’s MSN address.
function display_author_box() {
$msn_address = get_the_author_msn();
echo '<div class="author-box">';
echo '<h4>About the Author</h4>';
echo '<p>MSN Address: <strong>' . $msn_address . '</strong></p>';
echo '</div>';
}
add_action('the_content', 'display_author_box');
Display author’s MSN address in a widget
Create a widget to display the MSN address of the author in a sidebar or other widget area.
function author_msn_widget() {
register_widget('Author_MSN_Widget');
}
class Author_MSN_Widget extends WP_Widget {
function __construct() {
parent::__construct(false, 'Author MSN Address');
}
function widget($args, $instance) {
echo $args['before_widget'];
echo $args['before_title'] . 'Author MSN Address' . $args['after_title'];
echo '<p>' . get_the_author_msn() . '</p>';
echo $args['after_widget'];
}
}
add_action('widgets_init', 'author_msn_widget');
Display author’s MSN address only for a specific author
Show the MSN address only for a specific author by checking their username.
function display_specific_author_msn() {
$author_username = 'johnsmith';
if (get_the_author_meta('user_login') == $author_username) {
$msn_address = get_the_author_msn();
echo 'MSN Address: <strong>' . $msn_address . '</strong>';
}
}
add_action('the_content', 'display_specific_author_msn');