How to change the default value of shortcode_atts

58 views Asked by At

How change the default value of shortcode_atts.

Here is the function code that iam trying to change default value of shortcode_atts using add_filter.



function author_of_posts($atts) {

    $defaults = [
        'after' => '',
        'before' => '',
    ];
    $atts = shortcode_atts($defaults, $atts, 'post_author');

    $output = sprintf('%1$s<span class="author">%2$s</span>%3$s',
        $atts['before'],
        the_author(),
        $atts['after'],

    );

    return apply_filters('the_author_shortcode', $output, $atts);
}

Here iam trying to change default shortcode_atts value, using add filter.


add_filter('the_author_shortcode', 'change_shortcode_atts');

function change_shortcode_atts() {
    $atts['before'] = 'Writer';
    return $atts;
}
0

There are 0 answers