Skip to content

Instantly share code, notes, and snippets.

@billerickson
Last active January 4, 2019 02:09
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 billerickson/bb6e8ee63b007a9dd6fc to your computer and use it in GitHub Desktop.
Save billerickson/bb6e8ee63b007a9dd6fc to your computer and use it in GitHub Desktop.
<?php
/**
* Set Defaults in Display Posts Shortcode
* @see https://displayposts.com/2019/01/04/change-default-attributes/
*
* @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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment