Change Default Attributes in Display Posts Shortcode

<?php
/**
* Set Defaults in Display Posts Shortcode
*
* @param array $out, the output array of shortcode attributes (after user-defined and defaults have been combined)
* @param array $pairs, the supported attributes and their defaults
* @param array $atts, the user defined shortcode attributes
* @return array $out, modified output
*/
function be_dps_defaults( $out, $pairs, $atts ) {
$new_defaults = array(
'posts_per_page' => 20,
'include_excerpt' => true,
);
foreach( $new_defaults as $name => $default ) {
if( array_key_exists( $name, $atts ) )
$out[$name] = $atts[$name];
else
$out[$name] = $default;
}
return $out;
}
add_filter( 'shortcode_atts_display-posts', 'be_dps_defaults', 10, 3 );
view raw functions.php hosted with ❤ by GitHub

Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk