Skip to content

Instantly share code, notes, and snippets.

View rutger1140's full-sized avatar
🤖
Trying out Omarchy

Rutger rutger1140

🤖
Trying out Omarchy
View GitHub Profile
@rutger1140
rutger1140 / gist:3325385
Created August 11, 2012 15:55
Fix Ruby 1.9.3 gem compiling in Mountain Lion
sudo ln -sn /usr/bin/g++ /usr/bin/g++-4.2
sudo ln -sn /usr/bin/gcc /usr/bin/gcc-4.2
@rutger1140
rutger1140 / .maintenance
Created September 1, 2012 14:28
Wordpress maintenance mode
<?php
function is_user_logged_in() {
$loggedin = false;
foreach ( (array) $_COOKIE as $cookie => $value ) {
if ( stristr($cookie, 'wordpress_logged_in_') )
$loggedin = true;
}
return $loggedin;
}
if ( ! stristr($_SERVER['REQUEST_URI'], '/wp-admin') && ! stristr($_SERVER['REQUEST_URI'], '/wp-login.php') && ! is_user_logged_in() )
@rutger1140
rutger1140 / gist:3786576
Created September 26, 2012 07:21
Clean up Wordpress wp_nav_menu
// Put this in your functions.php file
// Reduce nav classes, leaving only 'current-menu-item'
function nav_class_filter( $var ) {
return is_array($var) ? array_intersect($var, array('current-menu-item')) : '';
}
add_filter('nav_menu_css_class', 'nav_class_filter', 100, 1);
// Add page slug as nav IDs
function nav_id_filter( $id, $item ) {
@rutger1140
rutger1140 / gist:3794061
Created September 27, 2012 13:40
Wordpress number of search results
<p>
Uw zoekopdracht &lsquo;<strong><?php the_search_query(); ?></strong>&rsquo;
gaf <em><?php
/* Show number of search results */
$res = &new WP_Query("s=$s&showposts=-1");
echo $res->post_count;
wp_reset_query();
?> resultaten</em>.
</p>
@rutger1140
rutger1140 / gist:3794491
Created September 27, 2012 15:03
Wordpress: filter on custom post type taxonomy in admin
function my_restrict_manage_posts() {
global $typenow;
$args=array( 'public' => true, '_builtin' => false );
$post_types = get_post_types($args);
if ( in_array($typenow, $post_types) ) {
$filters = get_object_taxonomies($typenow);
foreach ($filters as $tax_slug) {
$tax_obj = get_taxonomy($tax_slug);
wp_dropdown_categories(array(
'show_option_all' => __('Show All '.$tax_obj->label ),
@rutger1140
rutger1140 / wp-sidebars.php
Created October 8, 2012 08:42
Wordpress - sidebar for each page
<h1>sidebar.php</h1>
<?php
// Trigger sidebar for current page
if($sidebar_name = get_post_meta($post->ID, 'sidebar', true)){
dynamic_sidebar($sidebar_name);
}
?>
<h1>functions.php</h1>
<?php
@rutger1140
rutger1140 / gist:3985887
Created October 31, 2012 08:39
Wordpress - multiple copies with same database
// Put this code above the define('ABSPATH') line
/** Run 2 copies of WordPress from the same Database
*
* source: http://codex.wordpress.org/Running_a_Development_Copy_of_WordPress#Run_2_Copies_of_WordPress_from_the_same_Database
*/
function WP_LOCATION () {
$script_path = realpath(dirname($_SERVER['SCRIPT_FILENAME']));
$wp_base_path = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR);
$web_subfolder = substr( $script_path, strlen($wp_base_path));
@rutger1140
rutger1140 / emmet.md
Created November 16, 2012 13:28
emmet code snippets

Emmet snippets

emmet.io


HTML page

 #wrapper>(header>figure#logo(a>img[src=logo.png])+(nav>ul>li*4>a))+(div[role=main]>header>h1)+footer	
@rutger1140
rutger1140 / gist:4088716
Created November 16, 2012 16:27
Simple menu for Wordpress
// Put this in your functions.php file
/**
* Return simple markup for menu
*
* Returns:
* - HTML unordered list
* - Array with HTML links
*
* @param string $menuslug Menu slug, defined in WP
@rutger1140
rutger1140 / forms.less
Created December 5, 2012 08:55
Gravity Forms stylesheet in LESS
/*
----------------------------------------------------------------
Gravity Forms Front End Form Styles
Version 1.6.5.1
http: //www.gravityforms.com
updated: April 24, 2012 6:09 PM
Gravity Forms is a Rocketgenius project
copyright 2012 Rocketgenius Inc.