Skip to content

Instantly share code, notes, and snippets.

View leomuniz's full-sized avatar
👋
Hello

Léo Muniz leomuniz

👋
Hello
View GitHub Profile
@leomuniz
leomuniz / onlyNumbers.js
Last active March 30, 2024 00:53
JavaScript snippet to allow only numbers when typing in an input field
jQuery.fn.onlyNumbers = function() {
return this.each(function() {
jQuery(this).keydown(function(e) {
var key = e.charCode || e.keyCode || 0;
return (
key == 13 || // Enter
key == 189 || // Minus symbol (-)
key == 8 || // Backspace
key == 9 || // Tab
key == 46 || // Delete
@leomuniz
leomuniz / Javascript File Template for WordPress.md
Last active November 20, 2022 00:07
Basic Javascript file template for WordPress with jQuery

Javascript basic file template for WordPress with enqueue functions to add to both admin area or frontend and minification .min according to the site environment.

Note:

If you need to delay the moment to enqueue the style/script, just use wp_register_script or wp_register_style.

Then, when the time comes, enqueue it using wp_enqueue_script( 'script-handle' ); or wp_enqueue_style( 'style-handle' );. Handle is the first param of both the register and enqueue functions.

Example: Add CSS or JS file only if a shortcode is present.