Skip to content

Instantly share code, notes, and snippets.

View ThemeMetric's full-sized avatar
🏠
Freelancer

Sajjad Hossain ThemeMetric

🏠
Freelancer
View GitHub Profile
@ThemeMetric
ThemeMetric / Copy and download file from remote server to local
Created September 14, 2018 21:48
Copy and download file from remote server to local
<?php
if(!@copy('https://sajjadhossain.me/file.zip','./somefile.zip'))
// change the remote server link to your own file link
{
$errors= error_get_last();
echo "COPY ERROR: ".$errors['type'];
echo "<br />\n".$errors['message'];
} else {
echo "File copied from remote!";
}
@ThemeMetric
ThemeMetric / Show Last Modified Date in WordPress post
Last active September 14, 2018 21:54
Show Last Modified Date in WordPress post
// Pest this code snipest in theme functions php file
function show_last_modified_date( $content ) {
$original_time = get_the_time('U');
$modified_time = get_the_modified_time('U');
if ($modified_time >= $original_time + 86400) {
$updated_time = get_the_modified_time('h:i a');
$updated_day = get_the_modified_time('F jS, Y');
$modified_content .= '<p class="last-modified">Last updated on '. $updated_day . '</p>';
}
$modified_content .= $content;
@ThemeMetric
ThemeMetric / Remove Query string of css,js files
Last active September 14, 2018 21:53
Remove Query string of css/js files
// pest this function in your theme functions.php file
// Remove Query string of css/js files
function sss_rssv_scripts() {
global $wp_scripts;
if (!is_a($wp_scripts, 'WP_Scripts'))
return;
foreach ($wp_scripts->registered as $handle => $script)
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
global $wpdb;
$prefixd=$wpdb->prefix;
$table=$prefixd.'tbl_area';
@ThemeMetric
ThemeMetric / js.md
Created August 25, 2017 11:11 — forked from nuhil/js.md
Javascript Handbook

Javascript Handbook

A hand crafted markdown document contains all major Javascript topics covered, taken from different sources. Brush Up your JS memory.

Comments


Single line comments start with //. For multi-line commands, you use /* ... */

// This is a single line comment
@ThemeMetric
ThemeMetric / Change the Default Gravatar on WordPress
Created August 1, 2017 08:52
Change the Default Gravatar on WordPress
add_filter( 'avatar_defaults', 'wpb_new_gravatar' );
function wpb_new_gravatar ($avatar_defaults) {
$myavatar = 'http://example.com/wp-content/uploads/2017/01/wpb-default-gravatar.png';
$avatar_defaults[$myavatar] = "Default Gravatar";
return $avatar_defaults;
}
@ThemeMetric
ThemeMetric / woocommerce ajax cart update
Created August 1, 2017 08:50
woocommerce ajax cart update
function woocommerce_cart_link() {
global $woocommerce;
?>
<a href="<?php echo esc_url($woocommerce->cart->get_cart_url()); ?>" title="<?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?> <?php _e('in your shopping cart', 'woothemes'); ?>" class="cart-button ">
<span class="label"><?php esc_html_e('My Basket:', 'woothemes'); ?></span>
<?php echo esc_html($woocommerce->cart->get_cart_total()); ?>
<span class="items"><?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count); ?></span>
</a>
<?php
}
<?php
add_action( 'pre-upload-ui', 'get_the_post_type' );
function get_the_post_type() {
$post_type = isset( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : 'post';
set_transient( 'attached_post_type', $post_type );
}
add_filter( 'intermediate_image_sizes_advanced', 'add_image_size_for_post_type', 10 );
function add_image_size_for_post_type( $sizes ) {