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 / data-attributes.php
Created Jun 20, 2013
Update kses and TinyMCE to allow select data-* attributes in WordPress
View data-attributes.php
<?php
add_action( 'after_setup_theme', 'x_kses_allow_data_attributes_on_links' );
function x_kses_allow_data_attributes_on_links() {
global $allowedposttags;
$tags = array( 'a' );
$new_attributes = array(
'data-foo' => array(),
'data-bar' => array(),
@mjangda
mjangda / x_maybe_load_ad_busters.php
Created Jun 13, 2013
Load ad-busters from the theme if the REQUEST_URI matches one of the whitelisted requests.
View x_maybe_load_ad_busters.php
<?php
add_action( 'init', 'x_maybe_load_ad_busters' );
function x_maybe_load_ad_busters() {
$ad_busters = array(
'/adcentric/ifr_b.html',
'/atlas/atlas_rm.htm',
'/doubleclick/DARTIframe.html',
'/eyereturn/eyereturn.html',
@mjangda
mjangda / zoninator-cpt-support.php
Created Apr 25, 2013
Adding custom post types to be support in Zone Manager zones
View zoninator-cpt-support.php
<?php
add_action( 'zoninator_pre_init', function() {
add_post_type_support( 'book', 'zoninator_zones' );
} );
@mjangda
mjangda / liveblog-feed.php
Created Mar 5, 2013
Add Liveblog entries to the feed
View liveblog-feed.php
<?php
/**
* Output Liveblog entries as part of feed content
**/
if ( class_exists( 'WPCOM_Liveblog' ) )
add_filter( 'the_content_feed', 'x_add_liveblog_entries_to_feed_content' );
function x_add_liveblog_entries_to_feed_content( $content ) {
if ( WPCOM_Liveblog::is_liveblog_post() ) {
@mjangda
mjangda / sanitize-as-html.php
Last active Dec 14, 2015
Sanitize callback that treats data as HTML.
View sanitize-as-html.php
<?php
function x_custom_metadata_sanitize_as_html( $field_slug, $field, $object_type, $object_id, $value ) {
if ( is_array( $value ) )
$value = array_map( 'wp_filter_post_kses', $value );
else
$value = wp_filter_post_kses( $value );
return $value;
}
@mjangda
mjangda / dynamic-facebook-comments.js
Last active Jan 6, 2019
Dynamically load Facebook comments on your site (if you already have the FB API running)
View dynamic-facebook-comments.js
jQuery( function( $ ) {
if ( 'undefined' === typeof FB )
return;
if ( $( 'body' ).hasClass( 'single-post' ) || $( 'body' ).hasClass( 'page' ) ) {
var $comments_div = $( '<div/>' );
$comments_div.addClass( 'fb-comments' );
$comments_div.attr( 'data-href', document.location );
$comments_div.appendTo( $( '.primary-content' ) );
@mjangda
mjangda / cms_modify_default_delete_term_caps.php
Created Jan 16, 2013
Allow limiting deletion of terms.
View cms_modify_default_delete_term_caps.php
<?php
add_action( 'registered_taxonomy', 'cms_modify_default_delete_term_caps', 10, 3 );
function cms_modify_default_delete_term_caps( $taxonomy, $object_type, $args ) {
global $wp_taxonomies;
if ( 'category' == $taxonomy ) {
$wp_taxonomies[ $taxonomy ]->cap->delete_terms = 'cms-delete-terms';
}
}
View respond-js-cdn.php
<!--[if lte IE 9]>
<script src="<?php echo get_template_directory_uri(); ?>js/respond/respond.min.js"></script>
<link href="<?php echo get_template_directory_uri(); ?>/js/respond/respond-proxy.html" id="respond-proxy" rel="respond-proxy" />
<?php // need to load the following proxy files from the mapped domain for cross-domain handling ?>
<link href="<?php echo wpcom_vip_noncdn_uri( dirname( __FILE__ ) ); ?>/js/respond/respond.proxy.gif" id="respond-redirect" rel="respond-redirect" />
<script src="<?php echo wpcom_vip_noncdn_uri( dirname( __FILE__ ) ); ?>/js/respond/respond.proxy.js"></script>
<![endif]-->
@mjangda
mjangda / shuffle-posts.php
Created Nov 10, 2012
Randomize 100 most recent posts in PHP + a loop
View shuffle-posts.php
<?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 Nov 10, 2012
Add Jetpack share buttons to the top of the content
View jetpack-sharing-top.php
<?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;
}
You can’t perform that action at this time.