Last active
June 17, 2020 14:45
-
-
Save DigitalEssence/1a9973ce3738477689d1a05a5ca451ac to your computer and use it in GitHub Desktop.
WordPress - Enfold - PHP - Add Custom Shortcode
This file contains 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
// Add to functions.php | |
add_shortcode( 'de_shortcode', 'de_shortcode' ); | |
function de_shortcode() { | |
$buffer = '<h3>Post Titles</h3>'; | |
$q = new WP_Query(array( | |
'post_type' => 'post', | |
'posts_per_page' => 6 | |
)); | |
while ($q->have_posts()) { | |
$q->the_post(); | |
$buffer = $buffer. "<strong>" . get_the_title(). "</strong> - " . get_the_date() . '<br>'; | |
} | |
wp_reset_postdata(); | |
return $buffer; | |
} | |
//And in a Text Box add | |
[de_shortcode] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment