Skip to content

Instantly share code, notes, and snippets.

View flegfleg's full-sized avatar

Florian Egermann flegfleg

View GitHub Profile
@flegfleg
flegfleg / wp-custom-page-title.php
Created February 11, 2016 16:12
wordpress custom page title function
function custom_page_title( ) {
$id = get_parent_id();
$post = get_queried_object();
$postType = get_post_type_object(get_post_type($post));
if ( is_category() ) {
$title = single_cat_title( '', false ) ;
} elseif ( is_tag() ) {
@flegfleg
flegfleg / wp-add-archives-to-menu-editor.php
Created February 15, 2016 15:32
* Add Post Type archives as entries to the Wordpress Menu Editor (like: pages, categories, etc) * via http://stackoverflow.com/questions/20879401/how-to-add-custom-post-type-archive-to-menu
<?php
/*
* Add Post Type archives as entries to the Wordpress Menu Editor (like: pages, categories, etc)
* via http://stackoverflow.com/questions/20879401/how-to-add-custom-post-type-archive-to-menu
*/
function prefix_add_metabox_menu_posttype_archive(){
add_meta_box( 'prefix_metabox_menu_posttype_archive', __( 'Archives' ), 'prefix_metabox_menu_posttype_archive', 'nav-menus', 'side', 'default' );
}
<?php
/* functions.php */
add_filter( 'the_content', 'my_filter_function' ); // hook into the_content()
function my_filter_function( $content ){
$new_content = str_replace( 'old', 'new', $content ); // modify content
return $new_content;
}
@flegfleg
flegfleg / wp_body_class_by_meta.php
Created March 4, 2016 13:26
add a class to body by custom meta
function add_body_class_by_meta ( $classes ) {
global $post;
$custom_classes = array();
$meta_invert = get_post_meta( $post->ID, 'metabox_page_invert', TRUE );
if ( $meta_invert == 'on') {
$custom_classes = array('ab-dark');
}
$return = array_merge( $classes, $custom_classes );
return $return;
}
@flegfleg
flegfleg / image-orientation-class.js
Created March 4, 2016 16:50
add class portrait, landscape or square to each image
// add orientation classes to each image: landscape / portrait / square
$("img").each(function (i) {
var img_class;
var height = parseInt ( $(this).attr( "height" ) );
var width = parseInt ( $(this).attr( "width" ) );
if ( width > height ) {
img_class = 'landscape';
} else if ( width < height) {
img_class = 'portrait';
} else {
@flegfleg
flegfleg / load-template.php
Last active March 20, 2016 13:46
WP Load template from plugins folder
<?php
/* Load template from plugins folder
* via http://wordpress.stackexchange.com/questions/17385/custom-post-type-templates-from-plugin-folder
*/
function load_person_template($template) {
global $post;
// Is this a "my-custom-post-type" post?
@flegfleg
flegfleg / wp-emoji-remove.php
Created May 21, 2016 13:21
Prevent Wordpress from adding emoji and smiley js and css
// Prevent Wordpress from adding emoji and smiley js and css
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
<?php
sendMessage( „Hallo Jasper", $diekamp ) {
while ( $diekamp->status == „unavailable“) {
$egermann->wait( 1 day );
$egermann->daeumchendreh();
}
}
?>
@flegfleg
flegfleg / extract-csv-rows.py
Last active January 10, 2017 11:22
csv extract rows
# csv: extract rows and save as new csv
import csv
in_f = open('test.csv')
out_f = open('out.csv', 'wb')
reader = csv.DictReader(in_f)
# Define column names
@flegfleg
flegfleg / widgets.php
Last active February 12, 2017 15:16
wordpress widget boilderplate
<?php
/**
* Adds category_children_widget widget.
*/
class category_children_widget extends WP_Widget {
/**
* Register widget with WordPress.
*/