Hi @holby,
Can I ask what the other JS snippet roughly looks like?
Thread Starter
holby
(@holby)
Sure, here goes:
// Content Views - add custom script
add_action( 'wp_footer', 'cv_theme_custom_script', 999999 );
function cv_theme_custom_script() {
?>
<script>
jQuery( document ).ready( function ( $ ) {
$('.pt-cv-ctf-ev_stichtag').each(function(){
$(this).find('.pt-cv-ctf-value').css('width','100%');
$(this).closest('.pt-cv-ctf-column').css({'position': 'absolute', 'bottom': '30px', 'left': '0px', 'text-align': 'left'});
});
} );
</script>
<?php
}
I’d recommend wrapping your code in a function:
add_action( 'wp_head', function () { ?>
<script>
var my_very_unique_function_name = function ($) {
$('.pt-cv-ctf-ev_stichtag').each(function() {
$(this).find('.pt-cv-ctf-value').css('width','100%');
$(this).closest('.pt-cv-ctf-column').css({'position': 'absolute', 'bottom': '30px', 'left': '0px', 'text-align': 'left'});
});
};
</script>
}, 5 ); <?php
Then, you can just call this function when the page is loaded:
add_action( 'wp_footer', 'cv_theme_custom_script', 999999 );
function cv_theme_custom_script() { ?>
<script>
jQuery( document ).ready( function ( $ ) {
my_very_unique_function_name($);
} );
</script>
<?php
}
And you can also call it in response to an Ajax request:
add_action( 'wp_head', function () { ?>
<script>
$.ajaxComplete(function () {
// trigger the other JS snippet again after AJAX.
my_very_unique_function_name($);
});
</script>
<?php } );
Thread Starter
holby
(@holby)
Wow, thank you so much
there is a small error which I am sure is trivial but beyond my scope
In the first script on the last line:
Parse error: a syntax error, expecting "}"
Parse error: a syntax error, expecting ")"
Thank you again
My apologies, looks like something got messed up when I posted the code. Here’s a fixed version:
add_action( 'wp_head', function () { ?>
<script>
var my_very_unique_function_name = function ($) {
$('.pt-cv-ctf-ev_stichtag').each(function() {
$(this).find('.pt-cv-ctf-value').css('width','100%');
$(this).closest('.pt-cv-ctf-column').css({'position': 'absolute', 'bottom': '30px', 'left': '0px', 'text-align': 'left'});
});
};
</script>
<?php }, 5 );