Skip to content

Instantly share code, notes, and snippets.

Avatar

Alvaro Gómez Velasco mrfoxtalbot

View GitHub Profile
@mrfoxtalbot
mrfoxtalbot / wp-debug.php
Last active Dec 3, 2019
WordPress Debugging tips
View wp-debug.php
<?php
// Enable WP_DEBUG mode
define( 'WP_DEBUG', true );
// Enable Debug logging to the /wp-content/debug.log file
define( 'WP_DEBUG_LOG', true );
// Disable display of errors and warnings
define( 'WP_DEBUG_DISPLAY', false );
@mrfoxtalbot
mrfoxtalbot / jsaddinlinecss.js
Created Nov 25, 2019
JS Add inline CSS styles
View jsaddinlinecss.js
// Selecting element
var elem = document.getElementById("intro");
// Appling styles on element, not camelCase on attributes
elem.style.color = "blue";
elem.style.fontSize = "18px";
elem.style.fontWeight = "bold";
@mrfoxtalbot
mrfoxtalbot / jsaddcontent.js
Created Sep 14, 2019
JS Add or replace content on one or several HTML elements using a CSS selector
View jsaddcontent.js
document.querySelector('.haiku').innerText = ('This is a Haiku')
// This will replace the content inside the first element that matches that CSS selector.
document.querySelectorAll('.haiku')[2].innerText = ('This is a Haiku')
// This will add a (.haiku) to the third element that matches that CSS selector.
document.querySelectorAll('.haiku').forEach(function(i){i.innerText = ('This is a Haiku')})
// This will replace the content of all elements that match that CSS selector
//There are ways to add content before and after the existing content instead of replacing it
@mrfoxtalbot
mrfoxtalbot / jsaddname.js
Last active Sep 14, 2019
JS Add a classname to one or various element using a CSS selector
View jsaddname.js
document.querySelector('.foo').classList.add('mystyle')
// This will add a classname (.mystyle) to the first element that matches that CSS selector (.foo)
document.querySelectorAll('.foo')[2].classList.add('mystyle')
// This will add a classname (.mystyle) to the third element that matches that CSS selector.
document.querySelectorAll('.foo').forEach(function(i){i.classList.add('mystyle')})
// This will add a classname (.mystyle) to ALL elements that match that CSS selector.
@mrfoxtalbot
mrfoxtalbot / woocommerce-custom-login-redirect.php
Created May 30, 2019
Role based Custom Redirects for WooCommerce login
View woocommerce-custom-login-redirect.php
<?php
/**
* Redirect users to custom URL based on their role after login
*
* @param string $redirect
* @param object $user
* @return string
*/
function wc_custom_user_redirect( $redirect, $user ) {
// Get the first of all the roles assigned to the user
View gist:6e15323b00866301472929fda32a11c3
function mrfx_remove_post_dates() {
add_filter('the_date', '__return_false');
add_filter('the_time', '__return_false');
add_filter('the_modified_date', '__return_false');
add_filter('get_the_date', '__return_false');
add_filter('get_the_time', '__return_false');
add_filter('get_the_modified_date', '__return_false');
}
add_action('loop_start', 'mrfx_remove_post_dates');
@mrfoxtalbot
mrfoxtalbot / WordPress -User-Agent-Body-Classes.php
Created Aug 6, 2018
WordPress User Agent Body Classes (via Weiko)
View WordPress -User-Agent-Body-Classes.php
<?php function rves3_body_classes( $classes ) {
global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone;
if($is_lynx) $classes[] = 'lynx';
elseif($is_gecko) $classes[] = 'gecko';
elseif($is_opera) $classes[] = 'opera';
elseif($is_NS4) $classes[] = 'ns4';
elseif($is_safari) $classes[] = 'safari';
elseif($is_chrome) $classes[] = 'chrome';
elseif($is_IE) {
$classes[] = 'ie';
@mrfoxtalbot
mrfoxtalbot / RGPD-template-spanish.html
Last active May 25, 2018
Plantilla para crear una documento de protección de datos RGPD basado en el de Ayuda WordPress
View RGPD-template-spanish.html
hola
<p><tt>Última actualización: $FECHAACTUALIZACION</tt></p>
<h2><u>TITULAR DE LA WEB</u></h2>
<ul>
<li>Su denominación social es: $NOMBREDELAEMPRESA</li>
<li>Su CIF: $ELCIF</li>
<li>Su domicilio social es: $DIRECCIONDELAEMPRESA</li>
<li>Su actividad social es: $ACTIVIDADDELAWEB</li>
<li>Correo electrónico: $EMAILDECONTACTO</li>
@mrfoxtalbot
mrfoxtalbot / createuser.php
Created May 3, 2018
Generate a new WordPress user via FTP
View createuser.php
<?php function wpb_admin_account(){
$user = 'your-username';
$pass = 'your-password';
$email = 'name@domain.com';
if ( !username_exists( $user ) && !email_exists( $email ) ) {
$user_id = wp_create_user( $user, $pass, $email );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
} }
add_action('init','wpb_admin_account'); ?>
@mrfoxtalbot
mrfoxtalbot / acf-custom-taxonomy-terms-icons.php
Last active Mar 16, 2018
Use ACF to list term icons/images in a custom WordPress taxonomy
View acf-custom-taxonomy-terms-icons.php
<?php
// load all 'category' terms for the post
$terms = get_the_terms( get_the_ID(), 'nombre_taxonomia');
foreach ( $terms as $term ) {
echo ' <div class="tax-icons">';
// we will use the first term to load ACF data from
if( !empty($terms) ) {
$term = array_pop($terms);
$custom_field = get_field('nombre_campo_icono', $term );
echo '<img src="';