3

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

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

2 Answers 2

4

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 );
    }
}
0

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.