Last active
March 2, 2020 13:38
-
-
Save chocopie/c76704444f4f18ad9deae87544ca81fd to your computer and use it in GitHub Desktop.
Shortcode for showing latest post on a page (Wordpress)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getLatestPostHomepage() { | |
| global $post; | |
| $args = array( 'numberposts' => 1 ); | |
| $latestposts = get_posts($args); | |
| foreach ($latestposts as $post) { | |
| setup_postdata($post); | |
| echo the_title("<h2>","</h2>"); | |
| echo the_content(); | |
| } | |
| wp_reset_postdata(); | |
| } | |
| add_shortcode('LatestPostHomepage', 'getLatestPostHomepage'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment