WordPress / CF7 - Customising the Contact Form 7 ajax loader gif, depending on location

ban-geoengineering picture ban-geoengineering · Mar 19, 2015 · Viewed 12.5k times · Source

I am using the Contact Form 7 plugin on a web site, which has a contact form in the footer of every page and also a contact form in the main area of a dedicated Contact page.

I know how to customise the ajax loader gif in CF7...

function my_wpcf7_ajax_loader () { return get_stylesheet_directory_uri() . '/images/my-loader-image.gif'; } add_filter('wpcf7_ajax_loader', 'my_wpcf7_ajax_loader');

...but my problem is that I need to specify two different loader images - one for the footer form and one for the Contact page form. (The reason for this is because one form is on a white background and the other is on a red background, and despite experimenting with different loader gifs I don't think it is possible to have a loader gif that looks good on both.)

Answer

Pbinder picture Pbinder · Oct 2, 2016

Here's the solution: https://gist.github.com/tctc91/8271205

add_filter('wpcf7_ajax_loader', 'my_wpcf7_ajax_loader');

function my_wpcf7_ajax_loader () {
    return  network_home_url() . '/assets/themes/ips-helpdesk/images/ajax-loader.gif';
}