Can I pass dynamically to shortcode attributes like as the following example shows

[ authoorsposts  author = get_the_author_id(); ]
  • Unfortunately does is not possible. Any executable or dinamic code must be handle in the shortcode function as @hans-spieß suggets in his answer.
    – cybmeta
    Nov 24, 2015 at 11:18

2 Answers 2


Not quite like that, but you can achieve the same result if you use a pre-defined value or argument in your shortcode to act as a "flag":

[authoorsposts author="post"]

...then in your handler:

function wpse_209684_author( $atts ) {
    if ( ! empty( $atts['author'] ) ) {
        $author = $atts['author'];

        if ( $author === 'post' ) // Our flag, make $author the current post author
            $author = get_the_author_id();
        else // Otherwise just accept a hardcoded author ID
            $author = absint( $author );

You could access the author object inside the shortcode function:

$author = get_the_author();
//  access ID of author object like $author->ID

Since shortcodes are added in the content, your Php code would be escaped and won't execute.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.