Custom shortcodes ruin post data

I have this custom shortcode to show random read more link inside a post, but when i use the shortcode, the post detail (like tag, category, next post, previous post) is ruined (inaccurate). Any idea how to fix this?


// Add random read more shortcode
function random_read_more_shortcode() {
    $args = array(
        'post_type'      => 'post',
        'orderby'        => 'rand',
        'posts_per_page' => 1,
    );

    $the_query = new WP_Query($args);

    if ($the_query->have_posts()) {
        while ($the_query->have_posts()) {
            $the_query->the_post();

            return '<a href="' . get_permalink() . '" target="_blank" class="read-more-link"><div class="read-more-box"><span class="prefix">Lihat juga: </span><span class="title">' . get_the_title() . '</span></div></a>';
        }

        wp_reset_postdata();
    }
}
add_shortcode('random_read_more', 'random_read_more_shortcode');



Source link