Why is my JavaScript/jquery code in my Functions.php file only working on the first loaded post on my WordPress site?
WARNING: I am new to coding so I apologize if some of this does not make sense
I am working on a WordPress site where the content will be replaced each week (any posts, media or files are wiped from the WP environment each week, and then repopulated with all new content, and so on).
One of the main features of the post pages, is that I will have to copy and paste local URLs from a Word document directly into the WordPress post. Since the original hyperlinks lead to a file saved on my local system, the hyperlinks obviously do not link properly on the WordPress site. I have created a small script for this using REGEX concepts to automatically change hyperlinks depending on the category.
This code snip-it is saved in my functions.php file (loads locally saved script that does the actual link change magic):
Function load_js_assets_Tab2 () {
if( in_category('10')) {
wp_enqueue_script('tab2LinkReplace','https://hq-wpserver/wordpress/wp-content/tab2LinkReplace.js', array('jquery'), '', true);
}
}
add_action('wp_enqueue_scripts', 'load_js_assets_Tab2');
THE PROBLEM:
For some reason, this script only works on the first post I load, then does not apply to all the following auto loaded posts. No matter which post I click first, the script works, but will not for any following posts as I scroll down through the posts. The 'auto load next post' feature is built right into my template Newsblock (https://newsblocktheme.com/).
I am assuming this has something to do with the fact that the auto load next post feature is done via AJAX loading, but I have no idea how to fix this.
If any one has any suggestions, work arounds or ideas on how to approach this differently... I would really appreciate it!
Via Active questions tagged javascript - Stack Overflow https://ift.tt/WGO5NYF
Comments
Post a Comment