RIght-aligning text

Hi - I need to convert the wordpress function:
<?php the_author_posts_link(); ?>
into a shortcode. It displays the name of the author and links to their other posts.

I’ve gotten this far in the functions.php file:
function author_shortcode() {
return the_author_posts_link();
}
add_shortcode( ‘author’, ‘author_shortcode’ );

This works. I can enter the shortcode [author] into wordpress edit window for page, and it displays the author. Now my problem is I need a “by” before the author name, and I need it right-aligned.

This is how it should look (which was built into the theme) - author’s name as first block on post, right-aligned, with a “by” before it:
https://dev.greensmoothie.com/blend/energy

This is how it looks as my shortcode on a page (wrong) - the theme does not have any option to display author’s name on a page, only on a post. That’s why I have to do it in functions.php for pages:
https://dev.greensmoothie.com/

How do I add in the php a “by” before: return the_author_posts_link();
and how do I tell it to display that return as right-aligned?

Sorry my php knowledge is nearly zero. It took me hours to find that working php to convert a wordpress function into a shortcode. Thank you!

I got this far:
function author_shortcode() {
$name = 'by ';
echo 'by ';
return the_author_posts_link();
}
add_shortcode( ‘author’, ‘author_shortcode’ );

now my only problem is how to write textalign:right in the php? so the entire sentence will display right-aligned. It defaults to left.

I settled on this and the browser assumes a closing </p> since I couldn’t figure out how to put it in the php:

function author_shortcode() {
echo "<p style='text-align:right'>";
	$name = 'by ';
	echo 'by ';
	return the_author_posts_link();
}
add_shortcode( 'author', 'author_shortcode' );

So now everyone knows how to convert a wordpress function into a shortcode and how to align the shortcode on the page!

Sponsor our Newsletter | Privacy Policy | Terms of Service