0

I have a front page that is pretty long length-wise so I have enabled add_filter("gform_confirmation_anchor", create_function("","return true;")); in my functions.php file. This helps the Gravity Form return to form on validation or submission (which overrides the defaults which would normally just return you to the top of the page).

I am looking for a way to only execute this code on the front page...this is what I have tried (in my functions.php file):

if (is_front_page()) {
    add_filter("gform_confirmation_anchor", create_function("","return true;"));
}

But that continues to add the filter on every page...could anyone point me in the right direction?

Thanks,
Josh

1 Answer 1

1

I found the answer here: How to create a plugin that only operates on the home page?

I just had to wrap the filter in a function:

function gravity_forms() {
    if (is_front_page()) {
        add_filter("gform_confirmation_anchor", create_function("","return true;"));
    }
}
add_action('template_redirect', 'gravity_forms');


Thanks,
Josh

2
  • One little improvement to add - WP has some handy little functions to return true, false etc. They are __return_true(), __return_false(), __return_zero(), __return_empty_array(), __return_null(), and __return_empty_string(). So, you can simplify your code by using: add_filter( 'gform_confirmation_anchor', '__return_true' ); Jun 8, 2017 at 21:16
  • 1
    Thank you for sharing, definitely going to adjust the code :-) Jun 12, 2017 at 1:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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