Skip to content

Instantly share code, notes, and snippets.

View QROkes's full-sized avatar

Cristhian Martínez Ochoa QROkes

View GitHub Profile
@QROkes
QROkes / functions.php
Last active February 26, 2016 03:03
Add featured image in RSS feed (Wordpress)
//* Add featured image in RSS feed
add_filter('the_content_feed', 'qr_rss_featured');
function qr_rss_featured($content) {
global $post;
if( has_post_thumbnail($post->ID) )
$content = ' ' . get_the_post_thumbnail($post->ID, 'thumbnail') . ' ' . $content;
return $content;
}
@QROkes
QROkes / index.html
Created March 6, 2016 00:21
How to center an image (vertically & horizontally) on a simple HTML web page.
<!DOCTYPE html>
<html lang="es-MX">
<head>
<meta charset="UTF-8" />
<title>Tituo de la pagina</title>
<meta name="description" content="Agregar descripcion">
<style type="text/css"> <!--Fix width, height and margin -->
img {
width: 600px;
height: 340px;
@QROkes
QROkes / functions.php
Last active March 6, 2016 01:04
Modify header title-url depending on the visitor browser language (Wordpress - Genesis Framework)
//* Modify header title-url depending on WP site language - HTML5 Version (Genesis Framework)
add_filter( 'genesis_seo_title', 'qr_header_title', 10, 3 );
function qr_header_title( $title, $inside, $wrap ) {
// Default
$taitol = sprintf('<span class="custom-class">QR</span> %s', get_bloginfo( 'name' ));
$inside = sprintf( '<a href="https://qrokes.com/" title="%s">%s</a>', 'Inicio', $taitol );
$currentlang = get_bloginfo('language');
// English
if($currentlang=="en-US") {
$inside = sprintf( '<a href="https://qrokes.com/en/" title="%s">%s</a>', 'Home', $taitol );
@QROkes
QROkes / page_archive.php
Created March 6, 2016 01:50
Multilingual archive sitemap template (WordPress + Genesis Framework + Poylang)
<?php
/**
* Genesis Framework
* Multilingual archive sitemap template (page_archive.php)
**/
//* Template Name: Archive
// Remove standard post content output
remove_action( 'genesis_post_content', 'genesis_do_post_content' );
@QROkes
QROkes / functions.php
Created March 18, 2016 19:15
WordPress exclude posts from Loop.
add_action( 'pre_get_posts', 'qr_exclude_tagged_posts' );
function qr_exclude_tagged_posts( $query ) {
if ( $query->is_main_query() && $query->is_home() ) {
$query->set( 'tag__not_in', array( 63 ) );
}
}
@QROkes
QROkes / page.php
Created March 18, 2016 20:55
List custom taxonomy terms (WordPress)
<?php
$args = array( 'hide_empty=0' );
$terms = get_terms( 'my-taxonomy', $args );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
$count = count( $terms );
$i = 0;
$term_list = '<p class="term-list">Tags: ';
foreach ( $terms as $term ) {
$i++;
$term_list .= '<a href="' . esc_url( get_term_link( $term ) ) . '" alt="' . esc_attr( sprintf( __( 'View all post filed under - %s -', 'my_localization_domain' ), $term->name ) ) . '">' . $term->name . '</a>';
@QROkes
QROkes / functions.php
Created March 18, 2016 22:05
Genesis Simple Sidebars for Custom Post Types (WordPress + Genesis Framework)
<?php
add_action( 'genesis_before_sidebar_widget_area', 'qr_remove_default_sidebar' );
function qr_remove_default_sidebar() {
if ( get_post_type() == 'my-cpt' ) { // set CPT here
remove_action( 'genesis_sidebar', 'ss_do_sidebar' );
remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );
add_action( 'genesis_sidebar', 'qr_add_cpt_sidebar' );
}
}
function qr_add_cpt_sidebar() {
@QROkes
QROkes / file.php
Created March 25, 2016 02:23
Download the url to a local temp file and then process it with getimagesize so we can optimize browser layout
<?php
$img_url = 'http://someurl.com/image.jpg';
if ( !empty( $img_url ) ) {
$tmp_file = download_url( $img_url, 10 );
if ( !is_wp_error( $tmp_file ) ) {
$size = getimagesize( $tmp_file );
$img_width = $size[0];
$img_height = $size[1];
@QROkes
QROkes / functions.php
Created March 25, 2016 03:28
Sends an email notification when a comment receives a reply - WordPress
<?php
/* Based on: https://wordpress.org/plugins/comment-reply-email-notification/ */
add_action('wp_insert_comment', 'qr_comment_notification', 99, 2);
add_action('wp_set_comment_status','qr_comment_status_update', 99, 2);
add_filter('wp_mail_content_type', function($contentType) { return 'text/html'; });
/**
* Sends an email notification when a comment receives a reply
* @param int $commentId The comment ID
@QROkes
QROkes / functions.php
Created May 10, 2017 01:37
How to use Amazon SES in WordPress.
// Amazon SES (AWS) instead php mail.
add_action( 'phpmailer_init', 'qr_aws_ses_smtp' );
function qr_aws_ses_smtp( $phpmailer ) {
$phpmailer->isSMTP();
$phpmailer->Host = 'email-smtp.us-east-1.amazonaws.com';
$phpmailer->SMTPAuth = true;
$phpmailer->Port = 25;
$phpmailer->Username = 'AWS SES Credentials - username';
$phpmailer->Password = 'AWS SES Credentials - password';
$phpmailer->SMTPSecure = 'tls';