I am currently using the mail to sent the pdf and I want them to auto-download once the contact form is filled.
How can I achieve this?
I have already tried this, and it does not cater my need.
I also tries on_sent_ok: location ="pdf url" but nothing helps.
Put this code into your htaccess
<FilesMatch "\.(?i:pdf)$">
ForceType application/octet-stream
Header set Content-Disposition attachment
</FilesMatch>
add this code in your Additional Setting tab in contact form 7
on_sent_ok: "location = 'your pdf file path';"
Try this I thin its word for you
The use of on_sent_ok has been deprecated since 2017.
Instead you need to add a function to your functions.php file. Here is an example.
Replace the contactFormId (999) and the download path respectively for your needs.
add_action( 'wp_footer', 'example_download' );
function example_download() {
?>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
if ( '999' == event.detail.contactFormId ) {
window.open('https://www.example.com/wp-content/uploads/2021/05/my-document.php', '_self');
}
}, false );
</script>
<?php
}
Related
I have a form that's inserted into a template using shortcode
<?php echo do_shortcode('[contact-form-7 id="370" title="Contact form 1"]') ?>
I'm trying to setup an event so that when the form is submitted I can redirect the user to another page. I'm using the following;
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
location = 'http://example.com/';
}, false );
</script>
The problem is, when you submit the form, the whole page is reloaded so the event is never triggered because the form isn't submitted via an ajax call.
This is the first time I'm trying to integrate a form into Wordpress, so I think I may have missed something. There are no errors in the developer console in Chrome.
Somewhere in your theme (check functions.php) or your wp-config.php file, you need to look for and remove the following:
functions.php
add_filter( 'wpcf7_load_js', '__return_false' );
config.php
define( 'WPCF7_LOAD_JS', false );
These lines would prevent the default behavior of CF7.
My theme was missing;
Adding that solved the issue.
I'm developing a word press website and would prefer to redirect this default login link to another link instead as I have done up a pop-up sign in instead.
try to add this to your functions.php file and modify it with your link
add_filter( 'comment_form_defaults', function( $fields ) {
$fields['must_log_in'] = sprintf(
__( '<p class="must-log-in">
You must Register or
Login to post a comment.</p>'
),
wp_registration_url(),
wp_login_url( apply_filters( 'the_permalink', get_permalink() ) )
);
return $fields;
});
You have to find comments.php file in your theme's folder. There you need to find this message and change link's href.
If its a popup workflow then you need to hijack the click into the link in your Javascript and show the popup.
You do not provide a lot of information about yoru specific scenario so pelase let me provide some basic example below
$(function() {
$('.must-log-in a'),on('click', function(){
e.preventDefault();
//call the function to show the pop up here
});
});
I have an external page that reads a RSS feed for a tag. I can't change anything on the external page, so the challenge is to change the RSS feed on my side to match the requirements.
On the external page the 3 latest posts for a tag are shown, and at the end of the section (note: not after each post but after all 3 posts) there is a "View all" link. This link receives its value from the element in the feed, which is by default set to my blog homepage, e.g. http://myblog.com). For this specific tag the link should be http://myblog.com/tag/myspecialtag.
The requirement is that the "View all" link links to the tag page instead of the homepage.
My idea was to add a condition to the element to change the URL for this specific category. I tried to change the feed template as recommended here: Customizing feeds, but for some reason it doesn't change the template at all. The code I tried is the following:
remove_all_actions( 'do_feed_rss2' );
add_action( 'do_feed_rss2', 'change_feed_rss2', 10, 1 );
function change_feed_rss2( $for_comments ) {
$rss_template = get_template_directory() . '/feeds/feed-custom_rss2.php';
if( file_exists( $rss_template ) )
load_template( $rss_template );
else
do_feed_rss2( $for_comments ); // Call default function
}
Of course I created the custom feed template and stored it in the feeds directory in my theme.
As this didn't work I tried looking into filters/hooks but I couldn't find anything helpful regarding my issue. Any ideas on how to best solve this issue?
I came up with the following solution:
I created a new custom page template custom_rss-feed.php and copied the code from wp-includes/feed-rss.php into it. I assigned this template to a new page. Additionally I added a filter to get_bloginfo_rss like the following:
function alter_bloginfo_rss($value, $key) {
if ( $key === "url" &&
is_page_template("custom_rss-feed.php")
) {
return $value . "/my/custom/url";
}
return $value;
}
add_filter("get_bloginfo_rss", "alter_bloginfo_rss", 10, 2);
I am using Wp Store Locator plugin.And I have Modified it according my need.But I am stuck in redirection.
Basically this plugin works with short code.So at the time of listing my URL is like that : localhost/wordpress/?page_id=391
Now there is one link which is redirects me to http://localhost/wordpress/?wpsl_id=3
Here is code for that :
add_action("template_redirect", 'my_theme_redirect');
function my_theme_redirect() {
$dpath = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] ;
$templatefilename = 'single-store.php';
if (strpos($dpath,'wpsl_id') !== false){
$return_template = get_template_directory() .'/' .$templatefilename ;
//$nurl = get_permalink($return_template);
//echo $return_template; exit;
wp_redirect($return_template);
exit;
}
}
This code is not redirecting me to any-where.It stays on the same page localhost/wordpress/?page_id=391 What might be the issue?
Anyone can suggest me how can I direct to URL when it detects wpsl_id in the URL ? I want to redirect them to plugin's template folder where I have added a file for that.
EDITED :
I have added above code in the plugin file just above the short code. Hope I has nothing to do with this issue :)
The template name looks fine. You just need to register the template before you call it.
Add this filter so this will execute before your action:
add_filter( 'template_include', 'single-store' );
I have http://mysite.com/admin.php
There I check wether the user is admin or not.
In second case I send the user to the wp-login page like this:
blog.mysite.com/wp-login.php?redirect_to=http%3A%2F%2Fmysite.com/admin.php
I expect redirect back for admin.php but wordpress always send me to wp-admin control panel.
I have researched.
When the dest. host is not in filter
allowed_redirect_hosts
WP just redirect the user to wp-admin.
How can I add more hosts to the filter?
If I put this example from the WP Codex on functions.php it stops working.
(http://codex.wordpress.org/Plugin_API/Filter_Reference/allowed_redirect_hosts)
add_filter( 'allowed_redirect_hosts' , 'my_allowed_redirect_hosts' , 10 );
function my_allowed_redirect_hosts($content){
$content[] = 'blog.example.com';
$content[] = 'codex.example.com';
// wrong: $content[] = 'http://codex.example.com';
return $content;
}
Add the following in your functions.php:
function my_allowed_redirect_hosts($allowed_host) {
$allowed_host[] = 'anothersite.com';
$allowed_host[] = 'www.someotherwebsite.com';
return $allowed_host;
}
add_filter('allowed_redirect_hosts','my_allowed_redirect_hosts');
Replace anothersite.com and add new values accordingly.
If you're trying to redirect users in a normal page, you can make use of Wordpress's wp_redirect() function:
<?php
wp_redirect( $location, $status );
exit;
?>
Documentation: wp_redirect()
Hope this helps!
Finally it works!
What I was doing wrong is putting the code in the WP functions.php file, and not in my custom theme functions.php file.
Thanks all!