javascript - Jquery script in html page do not work -
i have php page in wp site, , trying add jquery script directly in php. , structure...**
<?php /* template name: gallery page */ ?> <?php get_header(); ?> <?php //here have working php code ?> //here html <script language="javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"> alert("hi"); </script> <?php endwhile; else : // no rows found endif; ?> <div class="spacing"></div> <?php get_footer(); ?>
anyone knows why javascript code dont work if set set in script,. while works if type
<script> alert("hi"); </script>
also: if link jquery in footer, , call external script in site code above, works. alert starts. knows why? seems correct did , struggling on this.
thanks in advance
remove language
script tag:
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
and make sure close script tag before call alert. remove alert altogether.
important note: since you're using wordpress don't have include jquery on page since comes wordpress start.
to include main.js
script file in wordpress;
functions.php
file<?php function include_my_scripts() { wp_enqueue_script('main', 'scripts/main.js', array('jquery'), '', true); } add_action('wp_enqueue_scripts', 'include_my_scripts'); ?>
this name script main
, , it's located @ scripts/main.js
, depends on jquery, has no version, , should included @ bottom of page.
check wordpress codex additional information.
also script including should done functions.php
, not templates.
Comments
Post a Comment