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 / keep-aspect-ratio-mixin.scss
Created February 14, 2016 03:03
Maintain Aspect Ratio Mixin
@mixin aspect-ratio($width, $height) {
position: relative;
&:before {
display: block;
content: "";
width: 100%;
padding-top: ($height / $width) * 100%;
}
> .content {
position: absolute;
@mrfoxtalbot
mrfoxtalbot / gist:5dbefd3bff58e48f81fa66eae27e359c
Created April 18, 2016 12:48
Get WordPress localization file from child theme
// Load translation files from your child theme instead of the parent theme
function my_child_theme_locale() {
load_child_theme_textdomain( 'total', get_stylesheet_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'my_child_theme_locale' );
@mrfoxtalbot
mrfoxtalbot / gist:ba5996ea2dc9ecb6391740dc3271239d
Last active April 20, 2016 13:59
Enque javascript in WordPress
function my_assets() {
wp_enqueue_script( 'myscriptid', get_stylesheet_directory_uri() . 'js/myscripts.js', array( 'jquery' ) );
}
add_action( 'wp_enqueue_scripts', 'my_assets' );
@mrfoxtalbot
mrfoxtalbot / gist:c930940b4bdc3759f9e4871d06cb0b2a
Created April 24, 2016 15:36
Enable shortocdes in widgets
add_filter('widget_text','do_shortcode');
add_filter( 'the_content', 'my_the_content_filter', 20 );
function my_the_content_filter( $content ) {
if ( is_single() )
{
global $post;
$field = get_fields($post_id);
$imgLnk=get_bloginfo( 'stylesheet_directory' );
$pgLnk=get_post_meta($post->ID, 'Button', true);
$content .= '<div class="cf-wrap">CF go here<br> ' .$field. '</div>';
}
@mrfoxtalbot
mrfoxtalbot / gist:ccfad42fc03c81f5e4faaf03960759c9
Created April 28, 2016 09:03
Renombrar tags y hacer jérarquicos
function wd_hierarchical_tags_register() {
// Maintain the built-in rewrite functionality of WordPress tags
global $wp_rewrite;
$rewrite = array(
'hierarchical' => false, // Maintains tag permalink structure
'slug' => get_option('tag_base') ? get_option('tag_base') : 'tag',
'with_front' => ! get_option('tag_base') || $wp_rewrite->using_index_permalinks(),
@mrfoxtalbot
mrfoxtalbot / Rename posts
Created April 28, 2016 09:04
Rename posts
add_action('init', 'renameCategory');
function renameCategory() {
global $wp_taxonomies;
$cat = $wp_taxonomies['category'];
$cat->label = 'Por Tipos';
$cat->labels->singular_name = 'Por Tipo';
$cat->labels->name = $cat->label;
$cat->labels->menu_name = $cat->label;
//…
@mrfoxtalbot
mrfoxtalbot / gist:7e7a230fb23e5bed23c8bd9e8581f806
Last active April 28, 2016 12:03
Filtrar Custom Post Types en el admin por custom taxonomy
<?php
/**
* Display a custom taxonomy dropdown in admin
* @author Mike Hemberger
* @link http://thestizmedia.com/custom-post-type-filter-admin-custom-taxonomy/
*/
add_action('restrict_manage_posts', 'tsm_filter_post_type_by_taxonomy');
function tsm_filter_post_type_by_taxonomy() {
global $typenow;
@mrfoxtalbot
mrfoxtalbot / gist:018137eeee59d9402431217d5eb65e40
Created April 30, 2016 23:14
Hacer que los posts hijos hereden los términos de los posts padres
/** Set Child Terms to Parent Terms **/
function set_parent_terms( $post_id, $post ) {
if ( 'publish' === $post->post_status && $post->post_parent > 0 ) {
$parent = get_post($post->post_parent);
if(!empty($parent)){
$taxonomies = get_object_taxonomies( $parent->post_type );
foreach ( (array) $taxonomies as $taxonomy ) {
$terms = wp_get_post_terms( $parent->ID, $taxonomy );
if ( !empty( $terms ) ) {
@mrfoxtalbot
mrfoxtalbot / gettoplevel.php
Created April 30, 2016 23:40
Get top level ancestor in hierarchical post
function get_topmost_parent($post_id){
$parent_id = get_post($post_id)->post_parent;
if($parent_id == 0){
return $post_id;
}else{
return get_topmost_parent($parent_id);
}
}