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: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 / 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: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;
@fikrirasyid
fikrirasyid / gist:695c155cdd4ee78760fc
Created September 12, 2014 06:01
WordPress - Modifying URL's Query String, The Easy Way
/**
* Modify URL's query string
*
* @param string url to be modified
* @param array of query strings
*
* @return string of modified url
*/
function fr_modify_url( $url = '', $query_string_args = array() ){
@fikrirasyid
fikrirasyid / WordPress: replace the_excerpt's [...] + change its words length
Created January 16, 2015 02:59
WordPress: replace the_excerpt's [...] + change its words length
/**
* Modifying excerpt's length
*
* @return int
*/
function yourtheme_excerpt_length(){
return 20;
}
add_filter( 'excerpt_length', 'yourtheme_excerpt_length' );
@fikrirasyid
fikrirasyid / gist:e64490a0f8784e7d3635
Created February 5, 2015 16:21
Force All Pages to Use HTTPS Using WordPress HTTPS Plugin
function force_ssl_for_all( $force_ssl, $post_id = 0, $url = '' ){
return true;
}
add_filter( 'force_ssl', 'force_ssl_for_all', 10, 3 );