WordPress.org

Support

Support » Themes and Templates » [Resolved] Filter an array

[Resolved] Filter an array

  • I get the basic idea of filters, but I’m stumped on filtering an array:

    function genesis_post_categories_shortcode( $atts ) {
    	$defaults = array(
    		'sep'    => ', ',
    		'before' => __( 'Filed Under: ', 'genesis' ),
    		'after'  => '',
    	);

    [Moderator Note: Please post code or markup snippets between backticks or use the code button.]

    How do I filter only the ‘before’ part of this function?

    Thanks in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Have you tried the support offerings of StudioPress, since this function is part of the commercial Genesis Theme?

    Hi,

    I think you want the apply_filters function…

    Here’s how your array will look with this filter in place:

    function genesis_post_categories_shortcode( $atts ) {
    	$defaults = array(
    		'sep'    => ', ',
    		'before' => apply_filters( 'filter_name', __( 'Filed Under: ', 'genesis' ) ),
    		'after'  => '',
    	);

    Just replace ‘filter_name’ with the name of the filter you wish to apply.

    In addition be sure whether the filter you are using requires additional variables as per the codex page I linked to above 🙂

    Hope this helps!

    – Greg

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Filter an array’ is closed to new replies.
Skip to toolbar