i'm adding a function in my child theme's functions.php file that will only work on a specific page.
i can successfully Enqueue a 3rd-party jquery script.
and i can successfully add my own bit of jquery/js.
but i'm wondering if i can add these two things within the same function wrapper.
so here's the part for adding the external script:
function custom_thing () {
if(is_page( 2138 )){
wp_enqueue_script('external-script', 'http://domain.com/external/script.js', array('jquery'), 0, true);
}}
add_action( 'wp_enqueue_scripts', 'custom_thing' );
and here's the extra bit of code i need that goes with the external script:
function custom_thing_addition () {
if(is_page( 2138 )){
?>
<script>
jQuery(document).ready(function($) {
$("div.specific").on('click', 'div.thing1', function () {
//do somethiing
});
});
</script>
<?php
}}
add_action( 'wp_footer', 'custom_thing_addition' );
can i combine these? perhaps something like this (tho this does NOT work)...
function custom_thing () {
if(is_page( 2138 )){
wp_enqueue_script('external-script', 'http://domain.com/external/script.js', array('jquery'), 0, true);
?>
<script>
jQuery(document).ready(function($) {
$("div.specific").on('click', 'div.thing1', function () {
//do somethiing
});
});
</script>
<?php
}}
add_action( 'wp_enqueue_scripts', 'custom_thing' );
thanks.