Skip to content

Instantly share code, notes, and snippets.

View mrfoxtalbot's full-sized avatar
🕊️

Alvaro Gómez Velasco mrfoxtalbot

🕊️
View GitHub Profile
@mrfoxtalbot
mrfoxtalbot / acf-custom-taxonomy-terms-icons.php
Last active March 16, 2018 11:01
Use ACF to list term icons/images in a custom WordPress taxonomy
<?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="';
@mrfoxtalbot
mrfoxtalbot / html-redirect.html
Created February 13, 2018 22:11
Plain HTML Redirect
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="refresh" content="0;URL=../new-page.htm" />
<title>Redirect to... title of new-page</title>
</head>
<body>
<h1>Re-directing...</h1>
<p>You are being re-directed, if nothing happens, please <a href="../new-page.htm">follow this link</a></p>
@mrfoxtalbot
mrfoxtalbot / remove-cf7-css-js.php
Created February 12, 2018 12:37
Remove Contact Form 7 Scripts and Stlyes
<?php
//You can set the value of this constant in your wp-config.php like this:
define('WPCF7_LOAD_JS', false);
//Likewise, you can control the loading of the CSS stylesheet with WPCF7_LOAD_CSS. Contact Form 7 does not load the CSS stylesheet when the value of WPCF7_LOAD_CSS is false (default: true). You can set it in the wp-config.php like this:
define('WPCF7_LOAD_CSS', false);
//Or, you can also disable the loading of the JavaScript and CSS by adding a few lines of code into your theme’s functions.php file, like this:
add_filter( 'wpcf7_load_js', '__return_false' );
add_filter( 'wpcf7_load_css', '__return_false' );
@mrfoxtalbot
mrfoxtalbot / redirect-cf7-submissiones-miltiple.php
Created January 19, 2018 11:44
Redirigir a otra página después de enviar un formlario de Contact Form 7 (distinguir a dónde si tienes varios formularios)
<?php add_action( 'wp_footer', 'mycustom_wp_footer' );
function mycustom_wp_footer() {
?>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
if ( '947' == event.detail.contactFormId ) { // Sends sumissions on form 947 to the first thank you page
location = 'https://www.example.com/thank-you-1/';
} else if ( '1070' == event.detail.contactFormId ) { // Sends submissions on form 1070 to the second thank you page
location = 'https://www.example.com/thank-you-2/';
@mrfoxtalbot
mrfoxtalbot / echo-audio-acf-wordpress.php
Created January 9, 2018 13:02
Mostrar un audio desde Advanced Custom Fields
<?php
$urldelaudio = get_field('nombre_campo_audio');
echo do_shortcode('[audio mp3="'.$urldelaudio.'"][/audio]');
?>
// Tiene que haber una manera más elengate y sencilla, pero esto funciona.
@mrfoxtalbot
mrfoxtalbot / upscale-wordpress-thumbnails.php
Created December 11, 2017 11:28
Crear miniaturas de WordPress incluso cuando la imagen orginal es pequeña (Upscale)
<?php
function image_crop_dimensions($default, $orig_w, $orig_h, $new_w, $new_h, $crop){
if ( !$crop ) return null; // let the wordpress default function handle this
$aspect_ratio = $orig_w / $orig_h;
$size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
$crop_w = round($new_w / $size_ratio);
$crop_h = round($new_h / $size_ratio);
@mrfoxtalbot
mrfoxtalbot / lets-encrypt-ssl-https-exception-redsys-gateway-payment-confirmation.php
Last active November 29, 2017 11:19
Excepción del forzado de redirección HTTPS usando Lets Encrypt + Really Simple SSL para que funcione la confirmación del pago de Redsys con el plugin Redsys Gateway #WooCommerce #WordPress
<?php
function rsssl_exclude_http_url($html) {
$html = str_replace(
'https://example.com/?wc-api=WC_Sermepa',
'http://example.com/?wc-api=WC_Sermepa', $html);
return $html;
}
add_filter('rsssl_fixer_output','rsssl_exclude_http_url');
// Sources:
@mrfoxtalbot
mrfoxtalbot / qtranslate.php
Created October 25, 2017 13:19 — forked from barbwiredmedia/qtranslate.php
Wordpress qTranslate plugin conditional for in the template. For in navigation menus use <!--:en-->Home<!--:--><!--:es-->Inicio<!--:--> as a switch
<?php if (qtrans_getLanguage() == 'en') { ?>
<!-- stuff for English -->
<?php } elseif (qtrans_getLanguage() == 'es') { ?>
<!-- other stuff Spanish -->
<?php } ?>
@mrfoxtalbot
mrfoxtalbot / term-meta-acf-term-archives.php
Last active October 24, 2017 10:46
Cómo mostrar term meta con ACF en listados por categoría (archive)
<?php
$term_id = get_queried_object()->term_id;
$post_id = 'nombretaxonomia_'.$term_id;
$customfield = get_field('nombre_del_campo_acf', $post_id);
echo $customfield;
?>
// Es necesario la barra baja despues del nombre de la taxonomia, para concatenar el ID del termino correctamente
@mrfoxtalbot
mrfoxtalbot / WordPress-user-mysql
Created October 20, 2017 21:56
Crear un usuario de WordPress desde MySQL
INSERT INTO `wp_users` (`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_status`)
VALUES ('username', MD5('unpassword123'), 'Nombre Apellido', '[email protected]', '0');
INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`)
VALUES (NULL, (Select max(id) FROM wp_users), 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');
// Surce: Cybmeta https://cybmeta.com/crear-administrador-en-wordpress-desde-mysql