{"id":746,"date":"2013-12-17T16:21:17","date_gmt":"2013-12-17T16:21:17","guid":{"rendered":"http:\/\/cruz.codecharismatic.com\/?p=746"},"modified":"2014-07-04T22:50:32","modified_gmt":"2014-07-04T22:50:32","slug":"solution-boilerplate-theme-for-wordpress-dig-labs-stripe-plugin-jquery-issues","status":"publish","type":"post","link":"https:\/\/codecharismatic.com\/solution-boilerplate-theme-for-wordpress-dig-labs-stripe-plugin-jquery-issues\/","title":{"rendered":"Solution: Boilerplate Theme for WordPress + Dig Labs Stripe Plugin jQuery Issues"},"content":{"rendered":"
I am currently working on a subscription-based WordPress installation. For this project I am using a theme called Boilerplate<\/a>. Users signup, pay their monthly fee (recurring or single payment) and get access to a set of restricted documents. After much research I settled on the follow plugins to handle payments and subscriptions.<\/p>\n The Problem<\/strong> The Solution<\/strong> Explanation<\/strong> So that’s about it. I do believe this solution would work for any plugin in general that conflicts with the Boilerplate theme. If you’ve run into similar issues with any plugin please do share your experience in the comments. Happy WordPressing!<\/p>\n","protected":false},"excerpt":{"rendered":" I am currently working on a subscription-based WordPress installation. For this project I am using a theme called Boilerplate. Users signup, pay their monthly fee (recurring or single payment) and get access to a set of restricted documents. After much…<\/span><\/p>\n\n
\nAfter installing both of them I ran into a problem where both the theme and the plugins were including jQuery at different times and different places and sometimes not at all. This broke jQuery for the entire site. The Stripe plugin payment form didn’t display correctly and you couldn’t submit it to run a payment. Also, some custom jQuery I had written stopped working too.<\/p>\n
\nAfter some back and forth with the Boilerplate theme developer (Thanks Aaron!) he came up with the following solution.<\/p>\n\n
\n<\/a><\/li>\n
\n<\/a><\/li>\n\r\nif (!jQuery) {\r\n\tdocument.write(unescape('%3Cscript src="\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.10.2\/jquery.min.js"%3E%3C\/script%3E'));\r\n}\r\nif (!jQuery) {\r\n\tdocument.write(unescape('%3Cscript src="http:\/\/your.domain.com\/wp-content\/themes\/boilerplate\/js\/jquery.js"%3E%3C\/script%3E'));\r\n}\r\n\r\nwindow.$ = $ || jQuery;\r\n<\/pre>\n<\/li>\n<\/ul>\n
\nSo, by default no jQuery is loaded by the Boilerplate theme. Once the custom JS file is included, it checks to see if jQuery has been defined. If not it loads it from the Google CDN. If that fails then it loads in your local copy. If you are on a page that uses either plugin listed above, then jQuery will have already been included. In this case when your custom JS file loads it checks and will see that jQuery is already loaded and will not include it again.<\/p>\n