Iladarsda
Iladarsda

Reputation: 10692

WordPress: the_content filter on the front-page.php

Any idea why the_content filter is not being applied when front-page.php file in use?

The code below in not getting executed when front-page.php in use; works with index.php, page.php etc..

function some_filter_name($content){

    echo "dummy text";
    return $content;

}
add_filter( 'the_content', 'some_filter_name' );


UPDATE: Make sure you are actually using the_content() on the page. the_content filter is only applied on the_content element - i.e. you have to use this in your template

Upvotes: 1

Views: 1574

Answers (1)

I think this might be because in front-page.php you don't call the proper hook.
In wordpress the add_filter function hooks a function to a specific filter action.
An example of filter action is the_content but this filter action needs to exist in any page that you want to use the custom function for.

Examples that you should have in your front-page.php that the add_filter can use to hook your custom function:

<?php the_content('Read more...'); ?>

and

<?php 
global $more;    // Declare global $more (before the loop).
$more = 0;       // Set (inside the loop) to display content above the more tag.
the_content("More...");
?>

Make sure that in front-page.php you call the_content hook and that the post/page/cpt content is displayed then you function callback should fire too, if not then the issue is not from the hook and needs extra debug.

Upvotes: 2

Related Questions