Nice scroll to wordpress

wordpress runs jquery in noconflicts mode which means that you either need to write your JS code using the jQuery function call $(document).ready( function() { jQuery(“html”).niceScroll(); } ); or the following syntax which define $ $(document).ready( function($) { $(“html”).niceScroll(); } );

How to securely add an Ajax button to a WP Admin page?

In this answer I created 2 buttons which are visually disabled and get an invalid nonce before submitting. <?php /* Plugin Name: Ajax Example */ add_action( ‘admin_notices’, ‘my_action_button’ ); define( ‘MY_ACTION_NONCE’, ‘my-action-‘ ); function my_action_button() { $id = 4321; $data = array( ‘data-nonce’ => wp_create_nonce( MY_ACTION_NONCE . $id ), ‘data-id’ => $id, ); echo get_submit_button( … Read more

jQuery functions only work on homepage

Replace this line: <img src=”https://wordpress.stackexchange.com/questions/285006/<?php header_image();?>” height=”120px;” width=”100px;” alt=””/ class=”siteLogo”> with the following, to fix the invalid / and dimensions. <img src=”https://wordpress.stackexchange.com/questions/285006/<?php header_image();?>” height=”120″ width=”100″ alt=”” class=”siteLogo” /> Replace this markup: <span class=”spanish”>español</span> | <span class=”english”>english</span> with the following: <span class=”spanish” data-target=”.topBar .spanishNav”>español</span> | <span class=”english” data-target=”.topBar .englishNav”>english</span> Change your JavaScript to the following: jQuery.noConflict(); … Read more

This jQuery snippet doesn’t seem to work with WordPress

the problem was in your variable define syntax and also you need to wrap your jQuery script into no conflict wrapper, try this jQuery(window).load(function($) { // your function }); or (function($) { // your function })(jQuery); complete working script (function($) { $(window).load(function() { var lightBox = $(‘#lightbox’); var lightBoxContent = $(‘#lb-content’); var positionLightbox = function() … Read more

Ajax not firing properly using Firefox, but works in Chrome

This is the barebones for an AJAX call and response. Take a look and make sure this is working on Chrome and Firefox for you — works for me. <?php // Some function for data we’ll pass function dgx_donate_get_countries_requiring_postal_code() { return “cc postal code stuff…”; } // Register everything add_action(‘init’, function () { // Add … Read more

Including jQuery in WordPress

1) Only include scripts via wp_head(). For your custom script, register and enqueue it as such: function mytheme_custom_scripts() { if ( ! is_admin() ) { $scriptsrc = get_stylesheet_directory_uri() . ‘/js/’; wp_register_script( ‘mytheme_custom’, $scriptsrc . ‘custom.js’ ); wp_enqueue_script( ‘mytheme_custom’ ); } } add_action( ‘after_setup_theme’, ‘mytheme_custom_scripts’ ); 2) You need to deregister core jQuery, and then register … Read more

Stylizing external SVG files with jQuery and CSS

Sorry to say, but it’s not possible, because none of the elements from the SVG are read in the DOM, so CSS and Javascript don’t see them. All it sees is the <img> block, none of its contents. You have to import your SVGs into the page to have them be able to be manipulated. … Read more

adding the full image path to a wordpress javascript file

well first of all, don’t directly inject a script tag like that, use wp_enqueue_script to add your javascript file. additional data can then be passed from php to javascript via the wp_localize_script function. function wpa_scripts() { wp_enqueue_script( ‘wpa_script’, get_template_directory_uri() . ‘/js/script.js’, array(‘jquery’), null, true ); $script_data = array( ‘image_path’ => get_template_directory_uri() . ‘/images/’ ); wp_localize_script( … Read more

Bind to WPSetAsThumbnail

Yes, on your 2nd question 🙂 From what I saw in set-post-thumbnail.dev.js, it appears that you only need to add a link/anchor with the wp-post-thumbnail class on it in your quick edit screen. And you will get the image faded inside that link when the ajax request completes. For alerting “bacon” after the ajax completes, … Read more