Skip to content

Instantly share code, notes, and snippets.

@cadic
cadic / test.php
Last active November 1, 2021 08:45
Testing post__not_in vs filtering
<?php
/**
* Plugin Name: Perf Test
* Text Domain: perf-test
* Domain Path: /languages
* Version: 0.1.0
*
* @package Perf_Test
*/
@cadic
cadic / wp-highlight-menu.php
Last active June 9, 2016 20:00
Wordpress: highlight "Blog" menu item when displaying single posts or archives
<?php function ml_menu_item_classes( $classes, $item, $args ) {
if( ( is_singular( 'post' ) || is_category() || is_tag() ) && $item->object_id == get_option( 'page_for_posts', 0 ) )
$classes[] = 'current-menu-item';
return array_unique( $classes );
}
add_filter( 'nav_menu_css_class', 'ml_menu_item_classes', 10, 3 );
@cadic
cadic / move-wordpress.sql
Last active November 12, 2015 07:01
Database update when copying Wordpress site directly
UPDATE wp_options SET option_value = replace( option_value, '//old-address.com', '//new-address.com' );
UPDATE wp_posts SET post_content = replace( post_content, '//old-address.com', '//new-address.com' );
UPDATE wp_postmeta SET meta_value = replace( meta_value, '//old-address.com', '//new-address.com' );
@cadic
cadic / ml_is_child_of.php
Created November 11, 2015 11:56
Wordpress: function returns true if current page is child of specified page
<?php
function ml_is_child_of( $parent_id, $post_id = null, $post_type = 'page' )
{
if ( !is_page() )
return false;
$post_id = ( $post_id ) ? $post_id : get_the_ID();
$ancestors = get_ancestors( $post_id, $post_type );
return in_array( $parent_id, $ancestors );
@cadic
cadic / ml-siblings-navi-widget.php
Created November 10, 2015 11:35
Child pages list widget
<?php
/*
Plugin Name: Siblings Navi Widget
Description: Widget with links to all childern of top-level parent or self page
Author: Max Lyuchin
Author URI: http://heartwp.com/
*/
class ML_SiblingsNaviWidget extends WP_Widget {
@cadic
cadic / ml-author-filter.php
Created November 5, 2015 15:22
Wordpress plugin filter posts by author
<?php
/*
Plugin Name: Author Filter
Description: Adds author dropdown to post list filters
Author: Max Lyuchin
Author URI: http://heartwp.com/
*/
add_action( 'restrict_manage_posts', 'ml_author_dropdown' );