- This topic has 5 replies, 2 voices, and was last updated 3 years, 8 months ago by Tom.
-
AuthorPosts
-
August 20, 2020 at 9:20 am #1411429James
I know this is likely out of the scope of your support but you all have been exceptionally helpful in the past. The most recent update of GP premium has changed the way you all have implemented the infinite scroll and I’m struggling to replicate the setup that was working previously.
Previously in the scripts.js file I was able to edit the history parameter to be “replace” instead of “false” such that the page numbers get updated when infinite scrolling:
$container.infiniteScroll( { path: '.nav-links .next', append: '#main article', history: 'replace', outlayer: msnry, loadOnScroll: $button.length ? false : true, button: $button.length ? '.load-more a' : null, scrollThreshold: $button.length ? false : 600, } );
But now the scripts.js file only contains the following and i haven’t figured out how to update it such that it replicates the previous behavior.
var infiniteScrollInit = generateBlog.infiniteScrollInit; infiniteScrollInit.outlayer = msnry; $container.infiniteScroll( infiniteScrollInit );
August 20, 2020 at 2:45 pm #1411824TomLead DeveloperLead DeveloperHi there,
You no longer need to change the core file, which is good!
Now you can do this:
add_filter( 'generate_blog_infinite_scroll_init', function( $args ) { $args['history'] = 'replace'; return $args; } );
Let me know if you need more info 🙂
August 21, 2020 at 3:25 am #1412318JamesThat worked – awesome. Yes, great that I don’t have to change the core files. One more question/feature request if I may. I’ve also added in the following code in the previous version of the scripts.js to try and track “virtual page views”, although I haven’t had much luck with the code itself working. Was wondering if there was a way to incorporate it via the add_filter or elsewhere besides modifying the core file?
$container.on( 'history.infiniteScroll', function() { ga( 'set', 'page', location.pathname ); ga( 'send', 'pageview' ); });
August 21, 2020 at 8:59 am #1412911TomLead DeveloperLead DeveloperThat’s tricky..
You could try this:
add_action( 'wp_enqueue_scripts', function() { $script = "var $container = $( '#main article' ).first().parent(); $container.on( 'history.infiniteScroll', function() { ga( 'set', 'page', location.pathname ); ga( 'send', 'pageview' ); });"; wp_add_inline_script( 'generate-blog', $script ); } );
That should add it after the HTTP request for the script in your HTML. Not 100% sure it will work, though.
August 22, 2020 at 2:13 am #1413574JamesSomething wrong with that code…
syntax error, unexpected ‘$container’ (T_VARIABLE), doesn’t like “$container.on( ‘history.infiniteScroll’, function() {“
August 22, 2020 at 9:44 am #1414016TomLead DeveloperLead DeveloperSorry about that, can you try now?
-
AuthorPosts
- You must be logged in to reply to this topic.