Archive

Monthly Archives: April 2011

Dave Ramsey lays out the U.S. Government???s budget for 2011:

The federal government will take in $2.173 trillion in 2011. That???s their income, and it sounds pretty good. Until, that is, you factor in that the federal government will spend $3.818 trillion during the year. So, just like many families, the government???s outgo exceeds their income???to the tune of $1.645 trillion in overspending. That???s called the deficit. Altogether, the government has $14.2 trillion in debt.

What would that look like if a typical household lived the same way?

If their household income was $55,000 per year, they???d be overspending by 43%. That is, they???d be making $55,000 but spending $96,500. That means in 2011, they???d add $41,500 of debt to their current credit card debt $366,000!

Now do you see why cutting a measly $38 Billion, or even $61 Billion is not going to cut it? The Republicans and Democrats in Congress need to face reality.

Advertisements

Okay, so you have WordPress setup to display all of your images using your favorite lightbox-inspired image viewer.  Now the only problem is that WordPress only gives you the option to link the image to the post, or link the image to the full file.  In order to link to the large file size—which is what you ultimately want—you must manually edit the HTML inserted into your post.  Unacceptable!

I set out to find a simple plugin, to no avail.  I figured I wasn’t the first person to come across this issue.  Since I couldn’t find exactly what I was looking for, it was time to write a custom function.

I dug around some of the core files and determined the code I wanted to change was the admin function image_link_input_fields(), located under wp-admin/includes/media.php.  I wanted the default URL to be the large image, and possibly while maintaining the ability to choose None, Original File, or Post.

Modifying the core file is not advisable, since you would have to re-apply changes every time you update WordPress.  Filters to the rescue!

The Solution

Here’s my solution.  Simply add this to your theme’s functions.php file:

add_filter('attachment_fields_to_edit',  'large_attachment_fields_to_edit', 0,  2);function large_attachment_fields_to_edit($fields, $post){        if (substr($post->post_mime_type,0,5) == 'image'){                $html = "<input type='text' class='text urlfield' name='attachments[$post->ID][url]' value='" . esc_attr(array_shift( wp_get_attachment_image_src($post->ID, 'large', false) )) . "' /><br />                                <button type='button' class='button urlnone' title=''>" . __('None') . "</button>                                <button type='button' class='button urlfile' title='".esc_attr(array_shift( wp_get_attachment_image_src($post->ID, 'large', false) ))."'>Large File URL</button>                                <button type='button' class='button urlfile' title='" . esc_attr(wp_get_attachment_url($post->ID)) . "'>" . __('Original File URL') . "</button>                                <button type='button' class='button urlpost' title='" . esc_attr(get_attachment_link($post->ID)) . "'>" . __('Post URL') . "</button>";                $fields['url']['html'] = $html;        }        return $fields;}

This will set the default URL for images to be the large image size, instead of the full image size.  It also adds buttons for None, Large File URL, Original File URL (full), and Post URL.

How it works

Basically, the only useful hook I could find was attachment_fields_to_edit.  It would allow me to modify the HTML generated on the “Add an Image” admin screen, right before the user inserts the image into the post.  Since I only wanted to change the URL field, I replaced $fields[‘url’][‘html’] completely.

The first part is the input field itself.  I wanted to set the default value to the large image.  I used wp_get_attachment_image_src() to pull the URL for the large image.

<input type='text' class='text urlfield' name='attachments[$post->ID][url]' value='" . esc_attr(array_shift( wp_get_attachment_image_src($post->ID, 'large', false) )) . "' />

Next, I simply copied some code from the WordPress core file to re-add the default buttons, along with another one for the large image.