Skip to content

Instantly share code, notes, and snippets.

View davidvandenbor's full-sized avatar

David van den Bor davidvandenbor

View GitHub Profile
@davidvandenbor
davidvandenbor / styleswitcher.php
Last active December 25, 2015 15:39
WordPress: styleswitcher custom fields
<?php
// Styleswitcher
global $post;
$styleswitch=get_post_meta($post->ID, 'styleswitch', true, null);
if ($styleswitch == "") {
$styleswitch="app";
}
wp_enqueue_style('roots_styleswitch', get_template_directory_uri() . '/assets/css/'.$styleswitch.'.css', false, null);
?>
@davidvandenbor
davidvandenbor / disable-wp-and-plugins-updates.php
Last active December 25, 2015 15:39
WordPress: Disable WP updates and plugin updates
<?php
// Disable WordPress updates and plugins updates
// @file functions.php
// disable updates
add_filter( 'pre_site_transient_update_plugins', create_function( '$a', "return null;" ) );
remove_action( 'load-update-core.php', 'wp_update_plugins' );
// or: Remove WordPress Update Notification
add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 );
add_filter( 'pre_option_update_core', create_function( '$a', "return null;" ) );
@davidvandenbor
davidvandenbor / hide_filter_wp-adminbar.php
Last active August 29, 2015 13:57
WordPress: Hide Adminbar at the front-end
<?php
/**
* Wordpress hook for hiding the WP Adminbar on the front end.
* @file functions.php
*/
add_filter('show_admin_bar', '__return_false');
?>
@davidvandenbor
davidvandenbor / autoreplace-uploaded-wp-image.php
Last active October 7, 2015 20:03
WordPress: Auto-replace uploaded image with large image size thumbnail
<?php
/**
* @author @david
* replace the WordPress "large" image with the uploaded image
* put this in your Wordpress functions.php file:
*/
function replace_uploaded_image($image_data) {
// if there is no large image : return
if (!isset($image_data['sizes']['large'])) return $image_data;
@davidvandenbor
davidvandenbor / hide_html.htaccess
Last active May 8, 2024 07:37
Apache: Hide HTML extension in URLs with htaccess
# This tag loads the rewrite module
<IfModule mod_rewrite.c>
# enable the rewrite engine
RewriteEngine On
# Set your root directory
RewriteBase /
# Remove the .html extension
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.html\ HTTP
RewriteRule (.*)\.html$ $1 [R=301]
@davidvandenbor
davidvandenbor / wp-query-ref.php
Last active October 13, 2015 17:26 — forked from luetkemj/wp-query-ref.php
WordPress: WP_Query arrays reference
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
* Source: https://core.trac.wordpress.org/browser/tags/3.9/src/wp-includes/query.php
*/
$args = array(
@davidvandenbor
davidvandenbor / wordpress_loops.php
Last active August 29, 2015 14:03 — forked from bencooling/Wordpress Loops
WordPress: Loops
<?php /* Main loop ------------------------------------------*/ ?>
<?php if (have_posts()) while (have_posts()): the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php // get_template_part( 'content', 'home' ); ?>
<?php endwhile; ?>
<?php /* Simple alter main loop ------------------------------------------*/ ?>
<?php query_posts('posts_per_page=1&post_type=locations'); ?>
@davidvandenbor
davidvandenbor / wp_query_standard_loop.php
Last active May 20, 2016 16:25
WordPress: WP_query loop
<?php
/* WP_QUERY, STANDARD
Because of how WordPress maintains information using global variables,
it's crucial that once you've crafted, executed, and processed your
own WP_Query function, you need to call this particular function to
restore information to the state that it was in prior to when you ran
your own query. This is so that WordPress continue looping through
information as needed in the template hierarchy, and so that data
isn't mangled or lost when rendering content later in a page
or on another page!
@davidvandenbor
davidvandenbor / facebook_like_button_shortcode.php
Created July 6, 2014 08:26
WordPress: Facebook Like button shortcode
<?php
/**
* shortcode voor eigen Facebook like button
* shortcode for a simple Facebook like button
* @author @david
*/
function david_facebook_like() {
return '<div id="fb-root"></div>
<div class="fb-like" data-href="http://www.yoursite.com" data-layout="button_count" data-action="like" data-show-faces="true" data-share="true"></div>';
}
@davidvandenbor
davidvandenbor / hide_parts_of_wp_admin_with_css.php
Last active August 29, 2015 14:03
WordPress: hide parts of WP admin with CSS
<?php
/**
* Hide parts of WP admin with CSS. Awesome! Use in functions.php
* CSS code gebruiken om delen van de admin voor klanten te verbergen
* @author @david
*/
function david_admin_head() {
echo '<link href="'.get_bloginfo( 'template_url' ).'/wp-admin.css" rel="stylesheet" type="text/css">';
}
add_action('admin_head', 'david_admin_head');