Skip to content

Instantly share code, notes, and snippets.

Mohammad Jangda mjangda

Block or report user

Report or block mjangda

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mjangda
mjangda / jetpack-mobile-override.php
Created Nov 7, 2012
Override Jetpack's mobile theme by loading your own.
View jetpack-mobile-override.php
<?php
add_filter( 'jetpack_mobile_stylesheet', function( $stylesheet, $theme ) {
return 'vip/mytheme-mobile';
} );
add_filter( 'jetpack_mobile_template', function ( $template, $theme ) {
return 'vip/mytheme-mobile';
// if our mobile theme is a child theme, we should return the parent:
// return 'pub/myparenttheme-mobile';
@mjangda
mjangda / disable-relevancy-search.php
Created Oct 26, 2012
Disables WordPress relevancy search and defaults order to chronological
View disable-relevancy-search.php
<?php
add_filter( 'posts_search_orderby', function( $search_orderby, $query ) {
return '';
}, 10, 2 );
@mjangda
mjangda / meta-and-category-query.php
Created Oct 15, 2012
Meta + category__in query
View meta-and-category-query.php
$args = array(
'category__in' => $cat_id_for_posts,
'meta_query' => array(
array(
'key' => $custom_field_key_show_in_sidebar,
'value' => $custom_field_value_show_in_sidebar,
),
),
);
@mjangda
mjangda / allow-ids.php
Last active Oct 9, 2015
Don't let kses strip out ids from section tags
View allow-ids.php
<?php
function x_allow_ids_on_tags() {
global $allowedposttags;
$tags = array( 'section', 'article' );
$new_attributes = array( 'id' => array() );
foreach ( $tags as $tag ) {
if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) )
$allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes );
@mjangda
mjangda / jetpack-loader.php
Created Aug 31, 2012
Manually load Jetpack modules (e.g. for dev or offline environments); drop this in your mu-plugins folder
View jetpack-loader.php
<?php
// TODO: don't run if Jetpack is active
add_action( 'plugins_loaded', function() {
if ( ! file_exists( WP_PLUGIN_DIR . '/jetpack/' ) )
return;
$modules = array(
'modules/contact-form.php',
'modules/shortcodes.php',
@mjangda
mjangda / custom-permalinks.php
Created Aug 20, 2012
Custom permalink structure for a bunch of post types
View custom-permalinks.php
@mjangda
mjangda / perm.php
Created Aug 20, 2012 — forked from whyisjake/perm.php
New Permalink
View perm.php
add_filter( 'pre_post_link', 'make__permalink', 10, 2 );
function make_new_permalink( $permalink, $post ) {
if ( 'page' == $post->post_type && in_array( $post->page_name, array( 'home-page', 'home-page-include' ) ) ) {
$permalink = 'http://makezine.com';
}
return $permalink;
}
@mjangda
mjangda / s-maintenance-mode.php
Created Aug 16, 2012
Custom WordPress maintenance mode that allows super admins access to the Dashboard
View s-maintenance-mode.php
<?php
add_action( 'init', 'x_maintenance_mode' );
function x_maintenance_mode() {
if ( defined( 'X_MAINTENANCE_MODE' ) && true === X_MAINTENANCE_MODE ) {
if ( is_super_admin() && is_admin() )
return;
die( 'Site is currently under maintenance' );
@mjangda
mjangda / zones-json-feed.php
Created Aug 13, 2012
Output a JSON Feed of posts in a zone
View zones-json-feed.php
<?php
// This will be accessible at /feed/zones-json/
add_feed( 'zones-json', 'x_render_zones_json_feed' );
function x_render_zones_json_feed() {
if ( function_exists( 'z_get_zone_query' ) ) {
$query = z_get_zone_query( 'zone-name' );
header('Content-type: application/json');
@mjangda
mjangda / php-shuffle.php
Created Jul 26, 2012
Shuffle a batch of posts in PHP instead of using orderby => rand with WP_Query
View php-shuffle.php
<?php
$testimonial = false;
$testimonials_query = new WP_Query( array( 'fields' => 'ids', 'posts_per_page' => 20 ) );
if ( ! empty ( $testimonials_query->posts ) ) {
$testimonials = $testimonials_query->posts;
shuffle( $testimonials );
$testimonial_id = array_shift( $testimonials );
$testimonial = get_post( $testimonial_id );
You can’t perform that action at this time.