如何插入MailChimp订阅弹窗表单
发表于 : 2024年 4月 14日 14:06
MailChimp的默认弹窗脚本可能会在使用jQuery / jQuery UI的WordPress网站上中断,
下面的代码是加载程序的替代实现,它强制 MailChimp 的弹窗脚本在页面加载时出现在所有其他脚本下方。
要使用它,请使用 MailChimp 提供的原始弹窗脚本并修改其中的baseUrl、uuid、lid,然后将其添加到theme options>General Settings>Footer Code部分
请注意,MailChimp会存储一年的cookie,以防止您在关闭或填写后重复看到弹出窗口。如果您正在对此进行测试,您可能需要清除 Cookie、使用其他浏览器或打开私人浏览器窗口,以便在关闭或填写表单后再次访问该表单时查看该表单。
下面的代码是加载程序的替代实现,它强制 MailChimp 的弹窗脚本在页面加载时出现在所有其他脚本下方。
要使用它,请使用 MailChimp 提供的原始弹窗脚本并修改其中的baseUrl、uuid、lid,然后将其添加到theme options>General Settings>Footer Code部分
代码: 全选
<script>
// Fill in your MailChimp popup settings below.
// These can be found in the original popup script from MailChimp.
var mailchimpConfig = {
baseUrl: 'mc.us1.list-manage.com',
uuid: 'a123456789abcdefghijklmno',
lid: '1abc12345a'
};
// No edits below this line are required
var chimpPopupLoader = document.createElement("script");
chimpPopupLoader.src = '//s3.amazonaws.com/downloads.mailchimp.com/js/signup-forms/popup/embed.js';
chimpPopupLoader.setAttribute('data-dojo-config', 'usePlainJson: true, isDebug: false');
var chimpPopup = document.createElement("script");
chimpPopup.appendChild(document.createTextNode('require(["mojo/signup-forms/Loader"], function (L) { L.start({"baseUrl": "' + mailchimpConfig.baseUrl + '", "uuid": "' + mailchimpConfig.uuid + '", "lid": "' + mailchimpConfig.lid + '"})});'));
jQuery(function ($) {
document.body.appendChild(chimpPopupLoader);
$(window).load(function () {
document.body.appendChild(chimpPopup);
});
});
</script>