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 / 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 / loop-con-shortocdes.html
Last active April 20, 2016 14:02
Simple Loop using Custom Content Shortcodes
// https://wordpress.org/plugins/custom-content-shortcode/
<div class="section group wrap">
[loop type=post category=my-category-slug count=10]
<div class="section group">
<div class="col span_1_of_2">
[field image size="image-size-name"]
</div>
<div class="col span_1_of_2">
<div class="fecha">[field date]</div>
@mrfoxtalbot
mrfoxtalbot / gist:c930940b4bdc3759f9e4871d06cb0b2a
Created April 24, 2016 15:36
Enable shortocdes in widgets
add_filter('widget_text','do_shortcode');
@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);
}
}
@mrfoxtalbot
mrfoxtalbot / amIgrandchild.php
Last active May 5, 2016 20:19
Check if page is grandchild
https://wordpress.org/support/topic/conditional-statement-is-page-a-grandchild?replies=6
http://wordpress.stackexchange.com/questions/182017/a-check-for-if-is-parent-page-if-has-children-if-has-grandchildren
<?php if( count(get_post_ancestors($post->ID)) == 2 ) echo 'this is grandchild of top page'; ?>
<?php if( count(get_post_ancestors($post->ID)) >= 2 ) echo 'this is grandchild of some page'; ?>
try and echo the post id before the code to see if it is the one of the page you are on:
maybe also add a is_page() conditional:
<?php
@mrfoxtalbot
mrfoxtalbot / gist:6754cd7220b4e368be7757ce5eba4704
Created July 17, 2016 11:24
Permitir que haya HTML en la descripción de las categorías de WordPress
foreach ( array( 'pre_term_description' ) as $filter ) {
remove_filter( $filter, 'wp_filter_kses' );
}
foreach ( array( 'term_description' ) as $filter ) {
remove_filter( $filter, 'wp_kses_data' );
}
@mrfoxtalbot
mrfoxtalbot / WP-menu-shortcode.php
Last active July 27, 2016 17:56
Insert a WordPress menu using a shortcode
<?php
function print_menu_shortcode($atts, $content = null) {
extract(shortcode_atts(array( 'name' => null, 'class' => null ), $atts));
return wp_nav_menu( array( 'menu' => $name, 'menu_class' => $class, 'echo' => false ) );
}
add_shortcode('menu', 'print_menu_shortcode');
?>
And then use this shortcode [menu name="main-menu"] (changin "main-menu" with your menu name)
@mrfoxtalbot
mrfoxtalbot / wp-Langauge-bodyclass.php
Created August 5, 2016 16:23
Add language based CSS class to body tag in WordPress
<?php
function append_language_class($classes){
$classes[] = ICL_LANGUAGE_CODE; //or however you want to name your class based on the language code
return $classes;
}
add_filter('body_class', 'append_language_class');
?>