Skip to content

Instantly share code, notes, and snippets.

Created March 6, 2014 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/9397162 to your computer and use it in GitHub Desktop.
Save anonymous/9397162 to your computer and use it in GitHub Desktop.
Patch for http://wordpress.org/plugins/ads-by-datafeedrcom/ which allows Javascript based ad rendering to occur at the end of the page instead of inline. This allows us to load jQuery and other JS in the footer instead of the head
diff -ruN ads-by-datafeedrcom/dfads.php ads-by-datafeedrcom-patched/dfads.php
--- ads-by-datafeedrcom/dfads.php 2014-02-26 04:24:06.000000000 +0000
+++ ads-by-datafeedrcom-patched/dfads.php 2014-03-06 19:06:35.000000000 +0000
@@ -46,7 +46,9 @@
// Load jQuery on front end pages.
function dfads_load_js() {
if ( !is_admin() ) {
- wp_enqueue_script( 'jquery' );
+ wp_register_script('dfads-render', plugins_url('js/render.js', __FILE__), array('jquery'), '1.0.10', true);
+ wp_enqueue_script( 'jquery' );
+ wp_enqueue_script( 'dfads-render' );
}
}
add_action( 'init', 'dfads_load_js' );
diff -ruN ads-by-datafeedrcom/inc/dfads.class.php ads-by-datafeedrcom-patched/inc/dfads.class.php
--- ads-by-datafeedrcom/inc/dfads.class.php 2014-02-26 04:24:06.000000000 +0000
+++ ads-by-datafeedrcom-patched/inc/dfads.class.php 2014-03-06 18:47:28.000000000 +0000
@@ -274,14 +274,10 @@
$args['return_javascript'] = '0';
$args['_block_id'] = $id;
$args['container_html'] = 'none'; // Set to 'none' so we don't display the container HTML twice.
-
+ $dfadsQuery = admin_url('admin-ajax.php?action=dfads_ajax_load_ads&'.http_build_query( $args ) );
+
return '
- <'.$this->args['container_html'].' id="'.$id.'" class="dfads-javascript-load"></'.$this->args['container_html'].'>
- <script>
- (function($) {
- $("#'.$id .'").load("'.admin_url( 'admin-ajax.php?action=dfads_ajax_load_ads&'.http_build_query( $args ) ).'" );
- })( jQuery );
- </script>
+ <'.$this->args['container_html'].' id="'.$id.'" class="dfads-javascript-load" data-dfads-query="'.$dfadsQuery.'"></'.$this->args['container_html'].'>
<noscript>'.dfads( http_build_query( $args ) ).'</noscript>
';
diff -ruN ads-by-datafeedrcom/js/render.js ads-by-datafeedrcom-patched/js/render.js
--- ads-by-datafeedrcom/js/render.js 1970-01-01 01:00:00.000000000 +0100
+++ ads-by-datafeedrcom-patched/js/render.js 2014-03-06 16:09:33.000000000 +0000
@@ -0,0 +1,7 @@
+(function($) {
+ $('.dfads-javascript-load').each(function() {
+ var elementId = $(this).attr('id');
+ var query = $(this).data('dfads-query');
+ $('#' + elementId).load(query);
+ });
+})( jQuery );
\ No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment