Hi @littlebear211
Where can we see your work in progress please? I assume you have enqueued bootstrap and dependencies if applicable?
https://testthemedesign.littleseabear.com/
Hi @littlepackage I just launched it for you to see.
Yep bootstrap is enqueued in the header, js script in functions:
**Functions.php**
function typechild_scripts(){
include( get_stylesheet_directory() . '/function-includes/inline-style.php' );
wp_add_inline_style( 'child-style', $inline_styles );
wp_enqueue_script( 'script', get_template_directory_uri() . '/assets/script.js', array ( 'jquery' ), 1.1, true);
}
add_action( 'wp_enqueue_scripts', 'typechild_scripts' );
**script.js**
jQuery( document ).ready( function( $ )
{
$('#firstcarousel').on('slide.bs.carousel', function (e) {
/*
CC 2.0 License Iatek LLC 2018
Attribution required
*/
var $e = $(e.relatedTarget);
var idx = $e.index();
console.log("IDX : " + idx);
var itemsPerSlide = 8;
var totalItems = $('.carousel-item').length;
if (idx >= totalItems-(itemsPerSlide-1)) {
var it = itemsPerSlide - (totalItems - idx);
for (var i=0; i<it; i++) {
// append slides to end
if (e.direction=="left") {
$('.carousel-item').eq(i).appendTo('.carousel-inner');
}
else {
$('.carousel-item').eq(0).appendTo('.carousel-inner');
}
}
}
});
**CSS**
@media (min-width: 768px) {
.carousel-inner .active,
.carousel-inner .active + .carousel-item,
.carousel-inner .active + .carousel-item + .carousel-item {
display: block;
}
.carousel-inner .carousel-item.active:not(.carousel-item-right):not(.carousel-item-left),
.carousel-inner .carousel-item.active:not(.carousel-item-right):not(.carousel-item-left) + .carousel-item,
.carousel-inner .carousel-item.active:not(.carousel-item-right):not(.carousel-item-left) + .carousel-item + .carousel-item {
transition: none;
margin-right: initial;
}
.carousel-inner .carousel-item-next,
.carousel-inner .carousel-item-prev {
position: relative;
transform: translate3d(0, 0, 0);
}
.carousel-inner .active.carousel-item + .carousel-item + .carousel-item + .carousel-item {
position: absolute;
top: 0;
right: -33.3333%;
z-index: -1;
display: block;
visibility: visible;
}
/* left or forward direction */
.active.carousel-item-left + .carousel-item-next.carousel-item-left,
.carousel-item-next.carousel-item-left + .carousel-item,
.carousel-item-next.carousel-item-left + .carousel-item + .carousel-item,
.carousel-item-next.carousel-item-left + .carousel-item + .carousel-item + .carousel-item {
position: relative;
transform: translate3d(-100%, 0, 0);
visibility: visible;
}
/* farthest right hidden item must be abso position for animations */
.carousel-inner .carousel-item-prev.carousel-item-right {
position: absolute;
top: 0;
left: 0;
z-index: -1;
display: block;
visibility: visible;
}
/* right or prev direction */
.active.carousel-item-right + .carousel-item-prev.carousel-item-right,
.carousel-item-prev.carousel-item-right + .carousel-item,
.carousel-item-prev.carousel-item-right + .carousel-item + .carousel-item,
.carousel-item-prev.carousel-item-right + .carousel-item + .carousel-item + .carousel-item {
position: relative;
transform: translate3d(100%, 0, 0);
visibility: visible;
display: block;
}}
OK…
https://testthemedesign.littleseabear.com/wp-content/themes/type/assets/scripts.js
should be a JavaScript file.
Same with slick.js: https://testthemedesign.littleseabear.com/slick/slick.min.js
It begins with HTML. Why?
Let’s start there and sort out why when these scripts are called, HTML files arise.
Hi @littlepackage, sorry I thought I enqued my scripts.js as a javascript file?
I have to call slick/slick.min.js too?
@littlebear211
Your scripts, if they are at https://testthemedesign.littleseabear.com/wp-content/themes/type/assets/scripts.js and https://testthemedesign.littleseabear.com/slick/slick.min.js should be scripts. Look at those URLS, or look in your file system (using FTP/SSH/cPanel however you’re doing it) and see that those files are not JavaScript files. They should ONLY include the scripts.
I don’t know if you need slick or not, but it has the same problem. You’ve got to sort that out.
I don’t have Slick in my directory, no idea why that’s come up. for the JS, this is what I have under
assets/scripts.js
/**
* File script.js.
*
*/
jQuery( document ).ready( function( $ )
{
$('#firstcarousel').on('slide.bs.carousel', function (e) {
/*
CC 2.0 License Iatek LLC 2018
Attribution required
*/
var $e = $(e.relatedTarget);
var idx = $e.index();
console.log("IDX : " + idx);
var itemsPerSlide = 8;
var totalItems = $('.carousel-item').length;
if (idx >= totalItems-(itemsPerSlide-1)) {
var it = itemsPerSlide - (totalItems - idx);
for (var i=0; i<it; i++) {
// append slides to end
if (e.direction=="left") {
$('.carousel-item').eq(i).appendTo('.carousel-inner');
}
else {
$('.carousel-item').eq(0).appendTo('.carousel-inner');
}
}
}
});
Yes to both. I followed the directory on my cpanel (the actual link just takes me to the webpage)
OK, I answered my own question. Type isn’t a child theme, but it really should be if you don’t want to lose your changes on your next theme update. If you want to make customizations like this, a first place to start would be to build a child theme. Or build this feature as a plugin.
Your “JS” file that you’ve tried to enqueue is not a JS file, or there is an error with how it’s being enqueued. Maybe try to enqueue it with a more unique name, not “script”.
Yes to both. I followed the directory on my cpanel (the actual link just takes me to the webpage)
The actual link should absolutely not take you to the webpage. It should take you to a page like this: https://stats.wp.com/e-202221.js but with your scripts.
doesn’t take me there for some reason. I used this as a child theme for a different website fine, so not sure why it’s not enquing properly at the moment. I’ll try the unique name
I’ve tried to enqueue it with a more unique name.
doesn’t take me there for some reason. I used this as a child theme for a different website fine, so not sure why it’s not enquing properly at the moment. I’ll try the unique name
Can you be more specific? What doesn’t take you where? What is your unique name? What is the new enqueue code?
If a file is at https://testthemedesign.littleseabear.com/wp-content/themes/type/assets/scripts.js
and you say this is the content:
/**
* File script.js.
*
*/
jQuery( document ).ready( function( $ )
{
$('#firstcarousel').on('slide.bs.carousel', function (e) {
/*
CC 2.0 License Iatek LLC 2018
Attribution required
*/
var $e = $(e.relatedTarget);
var idx = $e.index();
console.log("IDX : " + idx);
var itemsPerSlide = 8;
var totalItems = $('.carousel-item').length;
if (idx >= totalItems-(itemsPerSlide-1)) {
var it = itemsPerSlide - (totalItems - idx);
for (var i=0; i<it; i++) {
// append slides to end
if (e.direction=="left") {
$('.carousel-item').eq(i).appendTo('.carousel-inner');
}
else {
$('.carousel-item').eq(0).appendTo('.carousel-inner');
}
}
}
});
Then that should be the content. It should absolutely show that, and only that. No redirects should occur to HTML pages.
OK, great start… Your script loading is working now.
Perhaps ‘script’ is a forbidden handle for wp_enqueue_script() or you changed something else. Let me take another look now.
@littlepackage the script link from my site that you send me just takes me to the website.
the new name of the file is: customscripts.js and the code is:
add_action( 'wp_enqueue_scripts', 'add_child_javascript' );
function add_child_javascript() {
wp_enqueue_script( 'script', get_stylesheet_directory_uri() . '/assets/customscripts.js', array ( 'jquery' ), 1.1, true);
}