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 / 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:7946e4ca472986ecfed42fe30190c28b
Last active September 5, 2016 19:24
Hide menu elements in the wp-admin
//https://codex.wordpress.org/Function_Reference/remove_menu_page
<?php
function remove_menus(){
remove_menu_page( 'index.php' ); //Dashboard
remove_menu_page( 'jetpack' ); //Jetpack*
remove_menu_page( 'edit.php' ); //Posts
remove_menu_page( 'upload.php' ); //Media
remove_menu_page( 'edit.php?post_type=page' ); //Pages
@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 / disable-woocommerce-sticky-checkout.php
Last active June 17, 2017 21:13
Disable WooCommerce Sticky scroll in checkout
<?php
function removebadsticky_woocommerce_scripts() {
wp_deregister_script( 'storefront-sticky-payment');
}
add_action( 'wp_enqueue_scripts', 'removebadsticky_woocommerce_scripts' , 90 );
?>
@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');
?>
@mrfoxtalbot
mrfoxtalbot / Enqueue-parent-theme-stylesheet.php
Created August 6, 2016 11:12
Enqueue Parent theme´s stylesheet using PHP instead of a CSS @import
<?php
function parent_theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
add_action( 'wp_enqueue_scripts', 'parent_theme_enqueue_styles' );
?>
@mrfoxtalbot
mrfoxtalbot / html-markup-template-parameters.php
Created August 6, 2016 11:34
Add markup around WordPress template functions using parameters
/* Right way */
<?php the_title( '<h1>', '</h1>' ); ?>
/* Wrong way */
<h1> <?php the_title(); ?> </h1>
@mrfoxtalbot
mrfoxtalbot / gist:87e3aa64cbafb9a34c354e62cc117221
Created August 16, 2016 17:34 — forked from m/gist:bab8d366d2e826ba2311
freedom zero mark pilgrim text
Movable Type has never been Free Software, as defined by the Free Software
Foundation. It has never been open source software, as defined by the Open
Source Initiative. Six Apart survived and thrived in the blogging community
because Movable Type was “free enough.”
Many people misunderstand
Free Software and the GNU General Public License. Many people equate the GPL to
the boogeyman, because it’s “viral”, and that sounds like a bad thing.
@mrfoxtalbot
mrfoxtalbot / excerpt-lenght-by-cpt.php
Last active August 23, 2016 17:03
Different Excerpt Length For Different Custom Post Types
<?php
function yourownprefix_excerpt_length($length) {
global $post;
if ($post->post_type == 'post')
return 32;
else if ($post->post_type == 'products')
return 65;
else if ($post->post_type == 'testimonial')
return 75;