Skip to content

Instantly share code, notes, and snippets.

View om4james's full-sized avatar

James Collins om4james

View GitHub Profile
@om4james
om4james / attachment_url_to_postid-example.php
Last active December 17, 2015 11:28
attachment_url_to_postid() Simple Example
<?php
$attachment_id = attachment_url_to_postid( 'http://yourdomain.com/wp-content/uploads/myfile.pdf' );
if ( $attachment_id ) {
// This file was found in the WordPress media library
// In this example we are going to permanently delete this file from the WordPress media library.
// Please be careful if you are copying/pasting this example code!
wp_delete_attachment( $attachment_id, true );
@om4james
om4james / wp_is_mobile_example.php
Last active December 17, 2015 10:58
wp_is_mobile() example
<?php
if ( wp_is_mobile() ) {
// Visitor is on a mobile device
} else {
// Visitor is on a desktop (not mobile) device
}
?>
@om4james
om4james / custom.css
Created May 30, 2012 05:26
Google Chrome (Mac) - Disable Google search, Google mail ads, Facebook Ads, and Facebook Trending Articles
/* Add the following CSS rules to ~/Library/Application Support/Google/Chrome/Default/User StyleSheets/Custom.css */
/* Hide Google Mail Ads and right hand panel */
td.y3 { display: none; }
@om4james
om4james / 1_unsafe.php
Created May 5, 2012 00:02
WordPress String Translation Escaping Example
<?php
echo '<p>' . __('This is some text that needs to be translatable in my WordPress plugin', 'myplugin') . '</p>';
@om4james
om4james / mini-loops-2-recent-posts.html
Created October 5, 2011 08:44
Mini Loops Example: 2 recent posts displayed on home page
[miniloop number_posts=2]
<li>
<h2>{title}</h2>
{image from=thumb width=75 height=75 class=alignleft}{ml_excerpt wlength=35 up_to_more=1 after=More... space_between=1}</li>
[/miniloop]