1

Im working with a child-theme of Wordpress-Bootstrap by 320press.com I want to get rid of the lead class added to the first paragraph of the content.

I looked in Wordpress codex in these articles:

But im not so experienced in PHP, only HTML - so i cant really tell if its a filter or a function that i need to remove - i tried both solutions in above links, but i cant seem to get any of them to work.

This is the PHP from functions.php that adds the class

// Add lead class to first paragraph
function first_paragraph( $content ){
    global $post;

    // if we're on the homepage, don't add the lead class to the first paragraph of text
    if( is_page_template( 'page-homepage.php' ) )
        return $content;
    else
        return preg_replace('/<p([^>]+)?>/', '<p$1 class="lead">', $content, 1);
}
add_filter( 'the_content', 'first_paragraph' );
5

Your problem isn't that you did the wrong thing, it's that you did it at the wrong time. When it happens is important, not where.

In a child theme, the functions.php is loaded, then the parents, so you're doing this:

  1. Remove the first_paragraph function from the_content filter
  2. Add the first_paragraph function to the_content filter

Clearly this is the wrong way round. It's like building the penthouse of a skyscraper first then building the foundations second, it isn't going to work. Here you can't remove the filter because it hasn't been added yet

To get around this, remove the filter at a later point using an action/hook, e.g.:

// when the init hook fires
add_action( 'init', 'sillo_remove_that_filter' );

function sillo_remove_that_filter() {
    // remove the filter
    remove_filter( 'the_content', 'first_paragraph' );
}
|improve this answer|||||
  • 1
    Thanks alot, and thanks for the detailed explaination - it really helps for my understanding :) – Sillo Nov 14 '14 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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