i browsed all of stackoverflow but nothing i found explains my problem.
I got the following code constellation:
function get_current_page(){
$post_id = get_queried_object_id();
return $post_id;
}
function load_js_assets() {
switch(get_current_page()) {
case 2:
wp_enqueue_script('openMobileMenu', './openMobileMenu.js', false);
}
}
add_action('wp_enqueue_script', 'load_js_assets');
i try to wp_enqueue_script() but when i refresh my site the script neither loads, nor does it show up in the source code.
What is the reason for this?
Please help me out quickly
Kind regards,
Your Alwin
Related
Need help.
I am creating a div inside body>div>div .
Reference: Creating div in a nested class using javascript
Here's a link to my jsfiddle https://jsfiddle.net/41w8gjec/6/
Here's a link to the site https://bastioul.com/index.php/category/portfolio/ so you can see how the div is nested
Here's the wordpress classes.
class="archive category category-portfolio category-3 custom-background custom-header-image layout-two-column-default no-max-width"
>
class="hfeed"
>
class="site-content"
Here's my actual javascript code
function bastioul() {
var dirty = document.querySelector('.category-portfolio>.hfeed>.site-content');
var grime = dirty.appendChild(document.createElement('div'));
grime.id = "portfolionav";
}
if (window.addEventListener) {
window.addEventListener('load', bastioul, false);
} else {
window.attachEvent('onload', bastioul);
}
No error messages in jsfiddle. I don't know enough about coding as far as php/javascript/jQuery is concerned to go through wordpress js files to see if something is negating my code. Not exactly sure of the root cause of my problem because it works in jsfiddle, and there is no console errors when i inspect page. I tried to research about the problem, but it is a pretty specific problem.
Not exactly sure what else to try.
Okay I solved the issue by editing the functions.php for the wordpress theme I was using.
This is my php code.
wp_register_script( 'portfolionav', get_template_directory_uri() . '/portfolionav.js', array(), true );
wp_enqueue_script('portfolionav');
wp_footer();
note
I had a issue with this code because it automatically selects a library.
I used browsers inspect console error to show me what library was being called, and it was /themes/primer.
I uploaded my javascript to this library.
And now my script is running correctly on my Wordpress site.
I was not aware I had to add script by calling it in my php file when using Wordpress.
Still i cant get any result can you help me?
i want take screenshot in my webpage. well i used code below showed:
<script>
window.ready = function () { alert("It's loaded!");
<?php
$img = imagegrabscreen();
imagepng($img, 'screenshot.png');
?> }
</script>
but it saved black image. what i do for it.?
i got code from as link below:
click this link:
http://www.codedevelopr.com/articles/image-screenshots-php/
finally help me that
code as PHP or script to take screenshot and save that image.
if anyone show a way of answer for this problem.
thanks in advance
According to this stackoverflow post, the fucntion will only work for XP and lower.
Please check your system preferences and maybe your logs for additional information.
Ok so i have a simple jquery script im trying to load into wordpress i have other scripts already working but for some reason this one is not working. I have it working just on a simple html page but right when i put in wordpress.
Could someone help me and let me know why i keep getting unknown syntax error
jQuery(document).ready(function ($) {
jQuery(".comb-7").hover(function () {
$(this).find('.background-hover').toggle();
}
});
thanks for any help
This cant Work, you're missing the cloosing the bracket for the hover method
You don't close the hover method. Should be:
jQuery(document).ready(function($) {
$(".comb-7").hover(
function () { $(this).find('.background-hover').toggle(); });
});
I want to hide the slider (and a bit more) if someone uses the search module on my Joomla site and tried several solutions mentioned here on stackoverflow like: https://stackoverflow.com/a/1760605/1641903
Currently my code looks like this:
<script>
if (/\/search\//.test(window.location)) {
$('#hideonsearch').hide();
}
</script>
I wrapped the slider in <div id="hideonsearch> and tried mentioned jquery in both the body and head (just to be sure), but it doesn't seem to work as you guys can see here.
Any idea on how to get in working?
I saw in your web site that the jquery is not loaded when your code is being executed.
You must put your code in the "onload" function, or make sure the jquery is loaded before doing this.
window.onload = function () {
if (/\/search\//.test(window.location)) {
jQuery('#hideonsearch').hide();
}
};
Or you can use the pure javascript code that is better.
window.onload = function () {
if (/\/search\//.test(window.location)) {
document.getElementById("hideonsearch").style.display = "none";
}
};
I saw another error in your web site now, related to this code:
jQuery(document).ready(function(){
jQuery('.hasTooltip').tooltip({"html": true,"container": "body"});
});
error:
undefined is not a function
And it is related to the same problem, jQuery is not loaded, so you can use "window.onload".
used the api to add a button that plays 1 vimeo video on a page.
I added the Froogaloop plugin into my plugins.js file and am calling out to it on my main.js file.
Here's my code
ready = function(player_id) {
var playButton, player;
player = $f(player_id);
playButton = $('#playButton');
return playButton.on('click', function(e) {
e.preventDefault();
player.api('play');
});
};
$f(document.getElementById('player')).addEvent('ready', ready);
The problem I'm having is that any script after this will not run. The error JSHint gives me is '$f' is not defined
I've tried defining ($f = '')this, but it simply breaks the functionality (which makes sense why that would break it). Has anyone run into this issue before? Do you know of a fix?
Also note that the above code block works. It just has to be the very last thing in my main js file or else everything after it would break. It also won't pass JSHint. I get two '$f' is not defined. errors.
Any help would be greatly appreciated.
Thnx!
I was having this problem because I was including my script before including froogaloop.js.
It seems that $f is defined on that js.
If the error is just with JSHint, you can add the following comment to the top of the file to suppress the warning:
/*global $f:false */
You must connect the library
<script src="http://a.vimeocdn.com/js/froogaloop2.min.js"></script>
As drcord pointed out in his answer to this similar question:
You are either loading jQuery after this code or not at. You need to include jQuery before this script.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js></script>