WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Filter an array (3 posts)

  1. everlearners
    Member
    Posted 2 years ago #

    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.

  2. Chip Bennett
    Theme Review Admin
    Posted 2 years ago #

    Have you tried the support offerings of StudioPress, since this function is part of the commercial Genesis Theme?

  3. datdesignguy
    Member
    Posted 2 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic