Skip to content

Instantly share code, notes, and snippets.

View fikrirasyid's full-sized avatar
💭
writing commit messages

Fikri Rasyid fikrirasyid

💭
writing commit messages
View GitHub Profile
@fikrirasyid
fikrirasyid / gist:5116160
Created March 8, 2013 12:30
Meta box theme 27
/*
* --------------------------------------------------------------------------------------------------------------------------------
* CUSTOM META BOXES FOR EASIER CONTENT EDITING
* --------------------------------------------------------------------------------------------------------------------------------
*/
add_action( 'add_meta_boxes', 'wp_meta_boxes_add' );
function wp_meta_boxes_add(){
// Custom Meta Boxes for post-type post
add_meta_box( 'binus-meta-boxes', 'BINUS Meta Information', 'wp_meta_boxes', 'post', 'normal', 'high' );
}
@fikrirasyid
fikrirasyid / gist:bf52bafb19735bc59c9a
Created July 20, 2014 13:15
Simplest Way To Check Mobile Device Using Js
function is_touch_device() {
return 'ontouchstart' in window // works on most browsers
|| 'onmsgesturechange' in window; // works on ie10
};
@fikrirasyid
fikrirasyid / gist:0e4e8d72fcee17a2096c
Created July 22, 2014 06:59
Getting Current URL in WordPress
/**
* Get current URL
*
* @return string
*/
function current_url(){
global $wp;
$current_url = trailingslashit( home_url( $wp->request ) );
@fikrirasyid
fikrirasyid / removing-all-actions-from-hook
Created August 28, 2014 15:38
Removing All Actions From Hook
/**
* Unhook all action with some exception on wp_head and wp_footer
*/
function fr_unhook_wp_head_footer(){
global $wp_filter; // Where all the hooks and their actions are stored
// Actions that should not be removed from the wp_head hook
$wp_head_whitelist = array( 'wp_enqueue_scripts', 'wp_print_styles', 'wp_print_head_scripts' );
// Unhook actions from wp_head
@fikrirasyid
fikrirasyid / WordPress - Removing or Dequeueing All Stylesheets And Scripts on Particular Page
Last active August 29, 2015 14:05
WordPress - Removing / Dequeueing All Stylesheets And Scripts on Particular Page
/**
* Removing / Dequeueing All Stylesheets And Scripts on Particular Page
*
* @return void
*/
function fr_dequeue_enqueue_styles_scripts(){
global $wp_styles, $wp_scripts;
// Note: You may want to add some conditional tag so this will only happen on particular page
// Let's say you want to do this on contact page
@fikrirasyid
fikrirasyid / php get web page as code to be copy pasted
Created August 31, 2014 13:46
PHP: Get Web Page As Code To Be Copy-Pasted
<pre>
<?php echo htmlspecialchars( file_get_contents( $url_to_be_copy_pasted ) ); ?>
</pre>
@fikrirasyid
fikrirasyid / gist:10739e0241bfffeeaa91
Created September 2, 2014 00:10
WordPress: Use Custom Template From Plugins
/**
* Route single page to custom template
*
* @return string of path
*/
function fr_route_template( $single_template ){
// Put any conditional tag here. This one assumes you want to serve custom template for CPT titled "newsletter"'s single page
if( is_singular( 'newsletter' ) ){
@fikrirasyid
fikrirasyid / gist:9d1703d5d41325bf2ec5
Created September 6, 2014 17:35
PHP Code Snippets: Working With YouTube
/**
* Get YouTube Video ID by YouTube URL
*
* @param string YouTube video URL
*
* @return string YouTube video ID
*/
function get_youtube_id_by_url( $url ){
// Parse URL
$parsed_url = parse_url($url);
@fikrirasyid
fikrirasyid / gist:afbbce36a4ea726def64
Created September 6, 2014 17:54
Create Year / Month / Date Separator Between Posts
<?php
// Update the date in given condition
if( isset( $GLOBALS['wp_query'] ) && is_sticky() ){
$GLOBALS['wp_query']->has_sticky = true;
}
if( isset( $GLOBALS['wp_query'] ) && !is_sticky() ){
// Define date index
if( !isset( $GLOBALS['wp_query']->opus_date ) ){
@fikrirasyid
fikrirasyid / gist:d0b38c9e87797334b1ab
Last active August 29, 2015 14:06
WordPress: Custom Conditional Tag For Detecting Sign Up Page
/**
* Check if current page is signup page or not
*
* @return boolean
*/
function is_signup(){
global $wp;
if( 'wp-signup.php' == $wp->request ){
return true;