Shortcode header appears before content
-
I’m trying to create shortcode, that should display random post.
function zalgiris_random_post() { global $post; $args = array( 'orderby' => 'rand'); $myPosts = get_posts($args); $result = '<h2>Random post: </h2>'; $post = $myPosts[0]; $result .= the_title(); return $result; }
The problem is, that the title of the post actually appears before Random post header. Why that happens?
I’m also new, I found that if I remove global post from the top of the function, it doesn’t work. What global post is so special? Is it used to reference for a single post?
- The topic ‘Shortcode header appears before content’ is closed to new replies.