Skip to content

Instantly share code, notes, and snippets.

View muhfaris's full-sized avatar
:octocat:
Focusing

Muhammad Faris 'Afif muhfaris

:octocat:
Focusing
View GitHub Profile
@muhfaris
muhfaris / get_view.php
Created October 11, 2016 04:25
Get view post count - konversi ke hasil M atau K
/**
Setelah fungsi mendapatkan hasil view post
kemudian hasilnya berupa angka(count)
jika lebih dari 1000 atau 100000 akan di konversi
dengan fungsi round_numb()
*/
function get_viewcount(){
$view_ = (int) get_post_meta(get_the_ID(),'post_views_count', true);
$conv_view = isset( $view_ ) ? round_numb( $view_ ) : $view_;
echo " <div class='counter'>$conv_view</div>";
@muhfaris
muhfaris / rule_user.php
Created October 11, 2016 04:26
Rules User add Function
// Add a custom user role
$result = add_role( 'Contributor', __(
'Contributor' ),
array(
'publish_posts' => false, // Allows the user to publish, otherwise posts stays in draft mode
)
);
@muhfaris
muhfaris / jetpack_double_post.php
Created October 11, 2016 04:27
Jetpack error double post
function jetpack_infinite_scroll_query_args( $args ) {
$args['order'] = 'ASC';
$args['orderby'] = 'name';
return $args;
}
add_filter( 'infinite_scroll_query_args', 'jetpack_infinite_scroll_query_args' );
@muhfaris
muhfaris / potong_kar.php
Created October 11, 2016 04:31
Potong Panjang judul / title post
/**
fungsi ini untuk memotong ukuran judul / title yang panjang lebih dari 55 karakter,
karakter itu meliputi space dan huruf.
fungsi :
<?php potong_kar(get_the_title(),55,'...');?>
judul di potong jika lebih dari 55 dan selanjutnya akan di replace menggunkan tanda "..." (tanpa petik " ")
*/
function view_post(){
$related = ci_get_related_posts( get_the_ID(), 5 );
@muhfaris
muhfaris / back_to_start.js
Created October 12, 2016 23:26
Scroll kembali ke atas setelah refresh, jadi detelah di reloade halamannya. scroll yang tadinya di bawah kembali ke atas
$(document).ready(function(){
$('html, body').scrollTop(0);
$(window).on('load', function() {
setTimeout(function(){
$('html, body').scrollTop(0);
}, 0);
});
});
@muhfaris
muhfaris / fungsi_top_related_in_post.txt
Created October 17, 2016 05:16
Post related by tag, ini fungci untuk menampilkan post berdasarkan tag, yang akan di ambil hanya judul, link saja, tdk ada yg lainnya.
function ci_get_related_posts( $post_id, $related_count, $args = array() ) {
$args = wp_parse_args( (array) $args, array(
'orderby' => 'rand',
'return' => 'query', // Valid values are: 'query' (WP_Query object), 'array' (the arguments array)
) );
$related_args = array(
'post_type' => get_post_type( $post_id ),
'posts_per_page' => $related_count,
'post_status' => 'publish',
function ci_get_related_posts( $post_id, $related_count, $args = array() ) {
$args = wp_parse_args( (array) $args, array(
'orderby' => 'rand',
'return' => 'query', // Valid values are: 'query' (WP_Query object), 'array' (the arguments array)
) );
$related_args = array(
'post_type' => get_post_type( $post_id ),
'posts_per_page' => $related_count,
'post_status' => 'publish',
@muhfaris
muhfaris / wordpress_low-quality-image-placeholders_lqip.md
Created December 7, 2016 01:28 — forked from ctlcltd/wordpress_low-quality-image-placeholders_lqip.md
How to easily generate low quality image placeholders (lqip) in WordPress

#How to easily generate low quality image placeholders (lqip) in WordPress

I have made this function using the WP_Image_Editor class and I have filtered through the "wp_generate_attachment_metadata" hook. You can modify the "theme" namespace into function names with your theme name or in anyway you like.

Applying the filter directly to wp_generate_attachment_metadata the image placeholders are auto added into WordPress metadata, so when your add/modify/delete an image (or regenerate it via a plugin), it accomplishes to modify also to the image placeholders.

The use of the native theme support can prevent the generation of lqip or target specific image sizes to generate.

It contains an hook filter lqip_quality to modify the quality without have to modify the function.

@muhfaris
muhfaris / Share_frs
Last active December 8, 2016 09:52
Share in Mobile Only
//Js
jQuery(document).ready(function() {
if (jQuery(window).width() < 768) {
jQuery(".share-entry").addClass("active_share");
}else {
jQuery(".share-entry").removeClass("active_share");
}
});
//fungsi php masukkan ke function.php theme nanti
@muhfaris
muhfaris / other_Mobile.js
Created December 8, 2016 08:28
Update js in mobile share
jQuery(document).ready(function() {
console.log('try it - window ready');
function isMobile(a) {
return (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea