Skip to content

Instantly share code, notes, and snippets.

View mjangda's full-sized avatar

Mohammad Jangda mjangda

View GitHub Profile
@mjangda
mjangda / shuffle-posts.php
Created November 10, 2012 17:20
Randomize 100 most recent posts in PHP + a loop
<?php $query = new WP_Query( array( 'posts_per_page' => 100, 'fields' => 'ids' ) ); ?>
<?php if ( $query->have_posts() ) :
$post_ids = $query->posts;
shuffle( $post_ids );
$post_ids = array_splice( $post_ids, 0, 12 );
foreach ( $post_ids as $post_id ) :
$post = get_post( $post_id );
setup_postdata( $post );
?>
@mjangda
mjangda / jetpack-sharing-top.php
Created November 10, 2012 00:01
Add Jetpack share buttons to the top of the content
<?php
add_filter( 'the_content', 'x_add_sharing_to_content_top' );
function x_add_sharing_to_content_top( $content ) {
if ( function_exists( 'sharing_display') )
$content = sharing_display() . $content;
return $content;
}
@mjangda
mjangda / jetpack-mobile-override.php
Created November 7, 2012 15:45
Override Jetpack's mobile theme by loading your own.
<?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 October 26, 2012 19:27
Disables WordPress relevancy search and defaults order to chronological
<?php
add_filter( 'posts_search_orderby', function( $search_orderby, $query ) {
return '';
}, 10, 2 );
@mjangda
mjangda / meta-and-category-query.php
Created October 15, 2012 14:08
Meta + category__in query
$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 January 21, 2022 02:27
Don't let kses strip out ids from section tags
<?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 August 31, 2012 05:11
Manually load Jetpack modules (e.g. for dev or offline environments); drop this in your mu-plugins folder
<?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 August 20, 2012 22:29
Custom permalink structure for a bunch of post types
@mjangda
mjangda / perm.php
Created August 20, 2012 18:12 — forked from whyisjake/perm.php
New Permalink
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 August 16, 2012 14:28
Custom WordPress maintenance mode that allows super admins access to the Dashboard
<?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' );