Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

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

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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. :)

share|improve this answer
    
Yes very helpful. Can you apply your answer to this question? I asked this question just to understand how it works. So it would be awesome if you can spend some more time to give me the solution. Thanks –  Giri Dec 13 '11 at 18:46
    
Sorry i don't follow your other question, i'm really not sure what i'm seeing and what you're aiming to do there, it's just not clear to me. –  t31os Dec 13 '11 at 18:57
    
Bro i updated my question with screenshots. I explained as much as i can. Please check that page now. Thanks –  Giri Dec 13 '11 at 19:21
    
@t31os Hope you don't mind the edit - else maybe paragraph inside paragraphs would appear. :) –  kaiser Dec 13 '11 at 19:31
    
As much as i appreciate the update kaiser, seeing as the asker is new to filters it may only make things more confusing, appreciate your ingenuity all the same. –  t31os Dec 13 '11 at 19:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.