Skip to content

Instantly share code, notes, and snippets.

@SubZane
SubZane / Asset.php
Created August 23, 2012 14:38
WordPress: Image Custom Meta Property
add_action( 'add_meta_boxes', 'custom_meta_boxes' );
add_action( 'save_post', 'ExtraImageProperty_save' );
function custom_meta_boxes() {
add_meta_box('ExtraImageProperty', 'Extra Image Property', 'ExtraImageProperty', 'page');
}
function ExtraImageProperty() {
global $post;
$extra_image_url = get_post_meta($post->ID, 'extra_image_url', true);
@SubZane
SubZane / Asset.php
Created August 27, 2012 14:55
WordPress: get_attachment_id_from_src
function get_attachment_id_from_src ($src) {
global $wpdb;
$reg = "/-[0-9]+x[0-9]+?.(jpg|jpeg|png|gif)$/i";
$src1 = preg_replace($reg,'',$src);
if($src1 != $src){
$ext = pathinfo($src, PATHINFO_EXTENSION);
$src = $src1 . '.' .$ext;
}
$query = "SELECT ID FROM {$wpdb->posts} WHERE guid='$src'";
$id = $wpdb->get_var($query);
@SubZane
SubZane / gist:5896271
Created June 30, 2013 18:23
tar and bzip a folder and its subfolders
tar -c --bzip2 -f foo.tar.bz1 foo/
$myValue = '123';
// First you need to set the visual value, then you need to set it selected, this is retarted
$('#myselect').val($myValue).attr("selected", "selected");
sed 's/old/new/g' input.txt > output.txt
split -d -b 4300m backup.tar.bz2 backup.tar.bz2.
cat backup.tar.bz2.* > backup.tar.bz2
git tag -a v0.2.1 12edf74 -m "First internal release"
git push origin v0.2.1
@SubZane
SubZane / gist:7806413
Created December 5, 2013 14:58
regex find tags
/<\s*\/?\s*[p,span]\s*.*?>/g
@SubZane
SubZane / functions.php
Last active March 22, 2020 09:35
How to prevent WordPress to add image dimensions
<?php
add_filter( 'post_thumbnail_html', 'remove_thumbnail_dimensions', 10 );
add_filter( 'image_send_to_editor', 'remove_thumbnail_dimensions', 10 );
add_filter( 'the_content', 'remove_thumbnail_dimensions', 10 );
function remove_thumbnail_dimensions( $html ) {
$html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
return $html;
}
?>
// there is a solution for jQuery < 1.9.0, where you can use `$.browser`:
// https://gist.github.com/nathansmith/950767
// but jQuery removed `$.browser` in version 1.9.0, so you have to get another way:
function last_child() {
if (/msie [1-8]{1}[^0-9]/.test(navigator.userAgent.toLowerCase())) {
$('*:last-child').addClass('last-child');
}
}