Lazy Load Project Content
January 13, 2025 · AI Conversations
—
### **1. Create a Custom Project Detail Page Template**
In your theme directory, create a custom template for project details. For example:
– File: `single-project.php`
“`php
—
### **1. Enqueue JavaScript for Lazy Loading**
Add a script to handle the AJAX request in your theme's `functions.php` file:
“`php
function enqueue_lazy_load_script() {
wp_enqueue_script(
'lazy-load-project',
get_template_directory_uri() . '/js/lazy-load-project.js', // Adjust the path as needed
array('jquery'),
null,
true
);
// Localize the script with AJAX URL
wp_localize_script('lazy-load-project', 'ajax_object', array(
'ajax_url' => admin_url('admin-ajax.php')
));
}
add_action('wp_enqueue_scripts', 'enqueue_lazy_load_script');