Skip to content

Instantly share code, notes, and snippets.

View markoheijnen's full-sized avatar

Marko Heijnen markoheijnen

View GitHub Profile
@markoheijnen
markoheijnen / gist:2215557
Created March 27, 2012 12:53
Create span on last character of WordPress title
<?php
$string = get_the_title();
$last_character = $string[ strlen( $string ) - 1 ];
echo substr( $string, 0, -1 ) . '<span>' . $last_character . '</span>';
?>
@markoheijnen
markoheijnen / gist:2355637
Created April 10, 2012 23:36
Create a WordPress page without a database entry
<?php
add_action( 'generate_rewrite_rules', 'specialpage_rewrite' );
function specialpage_rewrite( $wp_rewrite ) {
$extra_rules = array(
'special-page/?$' => 'index.php?show_special_page=1',
);
$wp_rewrite->rules = $extra_rules + $wp_rewrite->rules;
@markoheijnen
markoheijnen / gist:2399864
Created April 16, 2012 16:40
Change Post to News
<?php
add_action( 'init', array( &$this, 'change_post_object_label' ), 0 );
add_action( 'admin_menu', array( &$this, 'change_post_menu_label' ), 0 );
add_filter( 'post_updated_messages', array( &$this, 'post_updated_messages') );
function change_post_menu_label() {
global $menu;
global $submenu;
if( isset( $menu[5], $submenu['edit.php'] ) ) {
@markoheijnen
markoheijnen / gist:2399898
Created April 16, 2012 16:46
Updating CDN when it is activated and the site using W3 Total cache
<?php
$cdn_activated = false;
if( function_exists( 'w3_instance' ) ) {
$cdn_activated = w3_instance('W3_Config')->get_boolean( 'cdn.enabled' );
@set_time_limit( w3_instance('W3_Config')->get_integer('timelimit.cdn_import') );
}
$upload_dir = wp_upload_dir();
$file = 'test/somefile.png';
$new_location = $upload_dir[ 'baseurl' ] . $file;
@markoheijnen
markoheijnen / gist:2407319
Created April 17, 2012 16:29
Get WordPress menu title by theme location
<?
function get_menu_title( $theme_location, $default_name = 'menu' ) {
if ( $theme_location && ( $locations = get_nav_menu_locations() ) && isset( $locations[ $theme_location ] ) ) {
$menu = wp_get_nav_menu_object( $locations[ $theme_location ] );
if( $menu && $menu->name ) {
return $menu->name;
}
}
@markoheijnen
markoheijnen / gist:2572299
Created May 1, 2012 23:16
Adding post type to the Recent post widget to WordPress 3.4+
<?php
add_action( 'in_widget_form', 'extend_recent_posts_form', 10, 3 );
add_filter( 'widget_update_callback', 'extend_recent_posts_update', 10, 4 );
add_filter( 'widget_title', 'extend_recent_posts_init_query_filter', 10, 3 );
add_filter( 'widget_posts_args', 'extend_recent_posts_query' );
function extend_recent_posts_form( $widget, $return, $instance ) {
if( ! is_a( $widget, 'WP_Widget_Recent_Posts' ) )
return;
@markoheijnen
markoheijnen / gist:2576124
Created May 2, 2012 12:07
Class to enable a nice way to let the user have a horizontal sidebar
<?php
class Sidebar_Horizontal {
public $end_row = '<div class="clearfix"></div>';
private $registered = array();
private $counter = array();
function __construct() {
add_filter( 'dynamic_sidebar_params', array( &$this, '_sidebar_params' ) );
@markoheijnen
markoheijnen / gist:2606505
Created May 6, 2012 00:15
Cool way to include jquery from google on WordPress
<?php
class Load_External {
private $jquery_path;
private function load_external_jquery() {
global $wp_scripts;
$schema = is_ssl() ? 'https://' : 'http://';
@markoheijnen
markoheijnen / gist:2688460
Created May 13, 2012 13:24
Cool widget class for WordPress
<?php
function rockstars_register_default_widget( $sidebar, $class_name, $settings ) {
global $rockstars_widgets;
if( !is_admin() ) {
return $rockstars_widgets->register_default_widget( $sidebar, $class_name, $settings );
}
return false;
}
@markoheijnen
markoheijnen / gist:2958522
Created June 20, 2012 07:02
Only show users own media files (little bit hackery)
<?php
add_action( 'pre_get_posts', 'media_filter_user' );
add_filter( 'query', 'media_filter_counter' );
// Main stuff that filters it
function media_filter_user( $query ) {
global $pagenow;
if( 'media-upload.php' == $pagenow ) {