Skip to content

Instantly share code, notes, and snippets.

<?php
// add hook
add_filter( 'wp_nav_menu_objects', 'my_wp_nav_menu_objects_sub_menu', 10, 2 );
// filter_hook function to react on sub_menu flag
function my_wp_nav_menu_objects_sub_menu( $sorted_menu_items, $args ) {
if ( isset( $args->sub_menu ) ) {
$root_id = 0;
@levymetal
levymetal / scss-syntax-test.scss
Created May 4, 2018 07:35
scss-syntax-test.scss
div,
%test,
.test,
#test-#{$test},
.test:not(.test),
.test:not(div),
.test[test] {}
&-test,
&.test {
@extend %test, .test;
@levymetal
levymetal / functions.php
Created March 29, 2018 00:30
Show a warning on the WordPress admin screen when a user uploads a PNG image to an ACF gallery, content area, or featured image.
<?php
/**
* Add a big fucking warning when the client uploads a PNG when they should
* be using a JPG
*/
function varga_62341_admin_png_warning() {
global $post_type;
echo '<script>var varga_62341_post_type="'.$post_type.'";</script>';
?>
@levymetal
levymetal / api-service.ts
Last active November 1, 2022 02:48
Example of using observable from within a Service on Ionic 2. Full blog post here: http://christianvarga.com/how-to-create-and-monitor-observables-in-ionic-2-service/
import { Injectable } from '@angular/core';
import { Http, Headers, RequestOptions } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/Rx';
@Injectable()
export class ApiService {
private errorObserver: any;
public error: any;
@levymetal
levymetal / app.component-partial.ts
Last active November 1, 2022 02:47
How to show the keyboard accessory bar in Ionic 2.0.0-rc.1. Full blog post here: http://christianvarga.com/how-to-show-the-ios-keyboard-accessory-bar-in-ionic-2-0-0-rc-1/
import { StatusBar, Splashscreen, Keyboard } from 'ionic-native';
<?php
// add hook
add_filter( 'wp_nav_menu_objects', 'my_wp_nav_menu_objects_sub_menu', 10, 2 );
// filter_hook function to react on sub_menu flag
function my_wp_nav_menu_objects_sub_menu( $sorted_menu_items, $args ) {
if ( isset( $args->sub_menu ) ) {
$current_id = 0;
$root_id = 0;
$('.flickity-slider').flickity({
draggable: Modernizr.touchevents
});
@levymetal
levymetal / twitter-cache.php
Last active November 1, 2022 02:44
Custom version of my twitter cache that works with multiple usernames. Original here: http://christianvarga.com/how-to-get-public-feeds-using-twitters-v1-1-api/#comment-2121870201
<?php
// call this script using a GET parameter, eg: http://your-domain.com/twitter-cache.php?screen_name=your_twitter_username
error_reporting( 0 ); // don't let any php errors ruin the feed
$username = $_GET['screen_name'];
$number_tweets = 4;
$feed = "https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name={$username}&count={$number_tweets}&include_rts=1";
$cache_file = dirname(__FILE__).'/cache/'.'twitter-cache-'.$username;
@levymetal
levymetal / functions.php
Last active November 1, 2022 02:43
Custom adaptation for my sub-menu script that allows you to force a specific sub-menu to be displayed. Full documentation here: http://christianvarga.com/how-to-get-submenu-items-from-a-wordpress-menu-based-on-parent-or-sibling/
<?php
/* usage
*
* wp_nav_menu( array(
* 'theme_location' => 'primary',
* 'sub_menu' => true,
* 'root_id' => id_of_menu_item
* ) );
*/
@levymetal
levymetal / functions.php
Last active November 1, 2022 02:43
Custom adaptation for my sub-menu script that treats first-level items as root-level items. Full documentation here: http://christianvarga.com/how-to-get-submenu-items-from-a-wordpress-menu-based-on-parent-or-sibling/
<?php
/** wp_nav_menu( array(
'theme_location' => 'primary',
'sub_menu' => true
) );
or
wp_nav_menu( array(