Some questions regarding filter

1) Take a look at this example

add_filter( "xxx_xxxxx", "blah_blah" );
function blah_blah(){
        echo "filter added";
    }

xxx_xxxxx can be anything like my_filter or it should be one of the name listed here.

Read More

2) Lets say i have some content in my theme outside the_content loop.

Example

<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>

        <div class="entry-content">
                <?php the_content(); ?>
        </div>

        <div class="custom-content">
                <p>Blah blah some text goes here</p>
        </div>

<?php endwhile; ?>

Is there a way to filter Blah blah some text goes here text?

Thanks

Related posts

Leave a Reply

1 comment

  1. It depends whether you’re trying to hook to an existing filter or hook to one you’ve made, looking at your second code sample suggests you’re asking about making your own filter.

    And, yes you can add your own, something like this is valid inside your loop.

    <?php echo apply_filters( 'my_blah_filter', '<p>Blah blah some text goes here</p>' ); ?>
    

    You can then hook that filter, as you would with regular WordPress filters, eg.

    add_filter( 'my_blah_filter', 'my_filter_for_blah' );
    function my_filter_for_blah( $filter_content ) {
        // Uncomment the next line to see the effect of not replacing it
        $filter_content = 'new content';
        return $filter_content;
    }
    add_filter( 'my_blah_filter', 'wpautop' );
    

    Let me know if that helps. 🙂