WordPress Featured Images With an Auto Width or Height

To display the featured image of a WordPress post you would use the following:

<? if ( has_post_thumbnail() ) the_post_thumbnail(); ?>

Within the the_post_thumbnail() method you can include arguments that allow for further customization of the featured image in WordPress – also referred to as post thumbnail.

One such argument documented in the WordPress Codex is defining the size. The thumbnail size can be defined in the following ways:

the_post_thumbnail('thumbnail');       // Thumbnail (default 150px x 150px max)
the_post_thumbnail('medium');          // Medium resolution (default 300px x 300px max)
the_post_thumbnail('large');           // Large resolution (default 640px x 640px max)
the_post_thumbnail('full');            // Full resolution (original size uploaded)

the_post_thumbnail( array(100,100) );  // Other resolutions

When using the string (i.e. ‘medium’) to define the size, WordPress will use the settings from your setup to define the image size. Your image size settings are configured in Settings > Media. One item to note is the image sizes are created at the time the image is uploaded. So if you change you media settings after you have uploaded images, they will not apply retroactively to the images that were previously uploaded.

The last example from above, “the_post_thumbnail( array(100,100) );”, allows you to define a specific width and height to that implementation of the_post_thumbnail(). The numeric values are defined width, height like -> array(width,height)

How do I use automatic width or height for the featured image?

If you are working with a responsive design or fluid layout, you may need to use ‘auto’ to define the width or height. To do so, you can pass the ‘auto’ string in place of the width of height of the size array.

<? if ( has_post_thumbnail() )  the_post_thumbnail( array(400,'auto') ); ?>

Remember that the ‘auto’ is a string, so the single tick (‘) needs to surround the ‘auto’ string.

More details on the featured image customization options can be found at the WordPress Codex for the_post_thumbnail.

How to Remove the Links Menu Item from the WordPress Menu

Many sites and some blogs do not use the Links Manager tool in WordPress, especially those using WordPress as a Content Management System. If that is the case, you might want to remove the Links menu item from the admin area of the site altogether.

How do I remove the Links menu item from the WordPress admin?

Place the following code in the functions.php file of your active theme:

<?php
	add_action( 'admin_menu', 'mytheme_remove_menu_pages' );
	function mytheme_remove_menu_pages() {
		remove_menu_page('link-manager.php');
	}
?>

The above code will remove the Links menu item from the WordPress admin. For more information on how you can use this action to remove other menu items, see the WordPress Codex on remove_menu_page().

Communication Error with WordPress iOS iPhone App

I ran into a frustrating issue with recent efforts to add additional blogs to my iPhone WordPress app.

When trying to add the blog, I would get it to authenticate in the “Add Blog” section; however when I tried to connect to the blog I would get a “Communication Error. bad username or password” error message. Specs on the configurations are WordPress 3.0.1 and iOS WordPress v2.6.3. My research in the WordPress forums uncovered this to be a known bug (albeit hard to reproduce and resolve) in the iOS WordPress app. User comments included various efforts to resolve the problem. The steps I walked through to get a resolution are outlined below.

My failed attempts to resolve this issue included:

  1. Removing and re-adding the blog in the WordPress iPhone app.
  2. Verifying correct username/password combination and changing the password.
  3. Verify in wp-admin (under Settings > Writing) that Atom Publishing Protocol and XML-RPC are enabled for the blog.
  4. Using both the www.domain.com and domain.com in the URL field of the “Add Blog” form of the iPhone App.
  5. Including “/wp-admin” in the blog URL in the “Add Blog” form of the iPhone App.

The Solution:

After some time and effort reviewing numerous forum posts to find a solution I ran across a user suggesting to include the path to the xmlprc file on the website. For my efforts here the “Add Blog” fields on the WordPress iPhone app were the following:

  • URL: domain.com/wp-admin
  • Username: admin_username
  • Password: site_password
  • XML-RPC: domain.com/xmlrpc.php

Note: adding “/wp-admin” the the domain in the URL field enabled visibility of the XML-RPC fields for me to add the absolute path to the file on the wordpress install.

Why does this work? I don’t really have a great explanation. I just thought that because I struggled so much in authenticating a blog that I might save someone time and effort by posting/sharing my experience here.