Skip to content

Instantly share code, notes, and snippets.

View kovshenin's full-sized avatar

Konstantin Kovshenin kovshenin

View GitHub Profile
<?php
$args = array(
'post_type' => 'post',
'tax_query' => array(
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'operator' => 'NOT IN'
'terms' => get_post_format_slugs(),
)
<?php
/*
Plugin Name: No-IP
Plugin URI: http://wordpress.org/support/topic/37363
Description: Causes WordPress to NOT save the IP address from ANY commenter. WordPress will instead record all comment IP addresses as '127.0.0.1'
Author: WP-Forums
Author URI: http://wordpress.org/support/
Version: 0.1
*/
<?php
/**
* Template Name: Movie Template
* Description: A Page Template for a movies pages.
*/
function get_page_mediablock( $url ) {
global $wp_embed;
return $wp_embed->run_shortcode( '[embed width="1200"]' . esc_url_raw( $url ) . '[/embed]' );
}
<?php
function get_my_video_embed( $post_id, $video_url ) {
global $wp_embed;
$key = '_my_video_' . md5( $video_url );
$cache = get_post_meta( $post_id, $key, true );
if ( ! empty( $cache ) )
return $cache;
var $button = jQuery( '#my-button' ),
test = Math.floor((Math.random()*2)+1);
if ( test == 1 )
$button.css( 'background', '#ff0000' ).data( 'test-value', 'red' );
else
$button.css( 'background', '#0000ff' ).data( 'test-value', 'blue' );
_gaq.push(['_trackEvent', 'My Button', 'Show', $button.data( 'test-value' )]);
$button.on( 'click', function() {
@kovshenin
kovshenin / page-parent.php
Created January 8, 2014 09:19
Append a link to the page parent at the end of the content when on children pages.
<?php
/**
* Plugin Name: Page Parent Link
*/
function my_the_content( $content ) {
$post = get_post();
if ( 'page' == $post->post_type && $post->post_parent > 0 ) {
$parent = new WP_Query( array(
'post_type' => 'page',
'post__in' => array( $post->post_parent ),
<?php
add_action( 'init', 'my_init' );
function my_init() {
register_post_type( 'book', array(
'public' => true,
'menu_icon' => 'dashicons-facebook',
) );
}
<?php
function set_custom_dashicon() {
?>
<style type="text/css">
#menu-posts-{post_type} .wp-menu-image:before {
content: '\f174';
}
</style>
<?php
<?php
/**
* Plugin Name: Custom Excerpt Length
*/
function custom_excerpt_length( $length ) {
return 10;
}
add_filter( 'excerpt_length', 'custom_excerpt_length' );
(function(){
var original_routes = wp.themes.routes;
wp.themes.routes = original_routes.extend({
initialize: function() {
this.route( 'theme/:directory/:slug', 'wpcomtheme', function( directory, slug ) {
wp.themes.Run.view.view.expand( directory + '/' + slug );
});
return original_routes.prototype.initialize.apply( this, arguments );
}