-
Notifications
You must be signed in to change notification settings - Fork 865
how to make my own javascript to work in front end #162
Comments
The gimmick with javascript in wordpress is that the JS files are enqueued, and then wordpress outputs all the JS for themes and plugins to the header or footer when a special function is called in the page template (or header.php/footer.php). In this theme, the enqueueing takes place in enqueue-scripts.php |
Hi Mr.James, Thanks for replying ..Now I understand the concept on how if (!function_exists('FoundationPress_scripts')) :
} On Fri, Dec 12, 2014 at 4:35 AM, James Barlow notifications@github.com
|
@VaniNair what @jmbarlow was trying to say was that you add your scripts to the existing enqueue-scripts.php file, leaving the existing format as is. You still need foundation, jquery, and modernizer - these are core to making the Foundation framework work within WordPress. if (!function_exists('FoundationPress_scripts')) :
function FoundationPress_scripts() {
// deregister the jquery version bundled with wordpress
wp_deregister_script( 'jquery' );
// register scripts
wp_register_script( 'modernizr', get_template_directory_uri() . '/js/modernizr/modernizr.min.js', array(), '1.0.0', false );
wp_register_script( 'jquery', get_template_directory_uri() . '/js/jquery/dist/jquery.min.js', array(), '1.0.0', false );
wp_register_script( 'foundation', get_template_directory_uri() . '/js/app.js', array('jquery'), '1.0.0', true );
**[Register your custom script here]**
// enqueue scripts
wp_enqueue_script('modernizr');
wp_enqueue_script('jquery');
wp_enqueue_script('foundation');
**[Enqueue your custom script here]**
}
add_action( 'wp_enqueue_scripts', 'FoundationPress_scripts' );
endif; Call your function by placing it either in the the footer.php file (depending on if you want it on every page), or at the bottom of your pagetemplate.php if you only want it called on that specific page. |
Hi, Sorry for causing trouble. I'm using my function below the default On Fri, Dec 12, 2014 at 2:11 PM, FlatspinZA notifications@github.com
|
I called my function in index.php like this: And it echoed "not working"; ,I think the javascript is in action ,however not working properly. The banner images not appearing. When I refresh the page ,it shows for a second then goes off. And the pagination bullets appearing same with the number of banners uploaded correctly. |
Look, I am no expert - you're probably better off waiting for someone else to give you advice, but this is how I got other Javascript to work:
I didn't mess around with functions.php, or enqueue-scripts.php at all. |
Good one. I forgot that the grunt process looks for custom js files. Do what @FlatspinZA said. |
Dear all, I don't have much knowledge in JavaScript nor in foundationpress.
|
@jmbarlow - the only reason I got it working is because of you, oh great one. ;) @VaniNair - You say you don't have much knowledge of JavaScript, yet you are trying implement custom JavaScript on a framework adapted for WordPress. I am not trying to be negative, but just the mere fact that you said you downloaded node.js says me to are flying in the dark a bit (not that I am not). I would suggest that before you try your custom JavaScript implementation in FoundationPress - get it working in ZURB Foundation first. Then, also before trying you custom JavaScript in FoundationPress, try implement some JavaScript that you know works 100%. Learn how to do that, then work on your own implementation. Try get this working: http://kenwheeler.github.io/slick/ in FoundationPress, because I know that works 100%. I don't think this is the place for asking people to show you exactly how to build something from scratch, more for specific issues. You need to know what things are, and their purpose - you can't dive in at the deep end on something as involved as FoundationPress. |
What @FlatspinZA said. |
Hi all, I inserted the below code in functions.php and it worked. Thanks. //my custom function wp_register_script( 'my_amazing_script', get_template_directory_uri() wp_enqueue_script('my_amazing_script'); } add_action( 'wp_enqueue_scripts', 'wpb_adding_scripts'); On Mon, Dec 15, 2014 at 1:18 AM, Ole Fredrik Lie notifications@github.com
|
As far as I remember, you don't need to register scripts if it's not a dependency of a later script which you would en queue. You would register your own version of jquery if you don't want to use the built in one, since you would call it as a dependency in custom scripts that you would enqueue with an "array('jquery')" argument. But you can directly en queue custom scripts, especially if they don't have other js library dependencies. What you did isn't wrong, it's just using a function that it can do without. function wpb_adding_scripts() { |
Good Day Everyone. I'm using FoundationPress as frontend and Wordpress as backend. I created a very simple plugin to upload image into the homepage. I've no issue with that. I can display them properly in the page I desired. However I wish to use little bit of javascript for the image slideshow.
However I've no clue on where on earth to locate my javascript files. I also noticed that I can't even find a single .js files in Foundationpress header or footer. I did some search but I cant comprehend any. Below are my script. Please somebody help me on this.Thanks a million.
I need to locate this in header:
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>This one probably before tag:
<script src="js/jquery.krakatoa.js"></script> <script> $(window).on('load',function(){ $('.krakatoa').krakatoa( { width: '1100px', height: '320', autoplay: true, loop: true, delay: 9000, //Slider on hold for 9 sec duration: 800, //Slider Transition Timer direction: -1, first: 9}); }); </script This is how I display image retrieved from database:The text was updated successfully, but these errors were encountered: