Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save DigitalEssence/1a9973ce3738477689d1a05a5ca451ac to your computer and use it in GitHub Desktop.
Save DigitalEssence/1a9973ce3738477689d1a05a5ca451ac to your computer and use it in GitHub Desktop.
WordPress - Enfold - PHP - Add Custom Shortcode
// 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