-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathThanks_redirection.php
More file actions
69 lines (50 loc) · 1.78 KB
/
Copy pathThanks_redirection.php
File metadata and controls
69 lines (50 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
location = 'http://example.com/';
}, false );
</script>
or
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
location = "<?php echo get_bloginfo('url'); ?>/thank-you";
}, false );
</script>
#Here is an example of the code for two different pages
<?php
add_action('wp_footer', 'cf7_footer_script');
//This function prints the JavaScript to the footer
function cf7_footer_script(){
//if page name is contact.
if ( is_page('11')) {?>
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
location = 'https://website.loudliv.com/thanks/';
}, false );
</script>
<?php } else if ( is_page('14')) /* if page name is download */ {?>
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
location = 'https://website.loudliv.com/thanks/';
}, false );
</script>
<?php }
}
#Here is an example of the code for two different pages USING FOR ID.
add_action( 'wp_footer', 'redirect_cf7' );
function redirect_cf7() {
?>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
if ( '101' == event.detail.contactFormId ) { //if the form if equals #101
location = 'https://www.example.com/thanks1/';
} else if ( '365' == event.detail.contactFormId ) { //if the form if equals #365
location = 'https://www.example.com/thanks2/';
} else if ( '987' == event.detail.contactFormId ) { //if the form if equals #987
location = 'https://www.example.com/thanks3/';
} else { // Default thank you page for all forms which are not 101, 365 or 987
location = 'https://www.example.com/thanks-main/';
}
}, false );
</script>
<?php
}