WordPress 3.2 – faster and lighter

This major release include some interesting updates, such as a redesigned admin interface and a new theme called “Twenty Eleven”…

This major release include some interesting updates, such as a redesigned admin interface and a new theme called “Twenty Eleven”. The primary focus on this update was however to make WordPress both faster and lighter. In order to accomplish that, the developers had to raise the system requirements from PHP 4.3 and MySQL 4.1.2 to PHP 5.2.4 och MySQL 5.

Among the other updates you will find:

  • Redesigned post editor with fullscreen button
  • Extended Admin bar
  • No more IE6 support
  • Incremental upgrades (=faster)
More info can be found in the 3.2 Codex and in the Trac milestone, which includes over 400 closed tickets.

How to list post attachments in WordPress

Here’s an example on how you can list documents uploaded to a specific post or page in WordPress using get_children.

Here’s an example on how you can list documents uploaded to a specific post or page in WordPress using get_children. Add the following code to your single.php or page.php file to list uploaded documents.

<?php
$attached_documents = get_children(array(
	'post_parent'    => get_the_ID(),
	'post_type'      => 'attachment',
	'numberposts'    => -1, // show all
	'post_status'    => null,
	'post_mime_type' => 'application/pdf,application/msword,application/vnd.ms-powerpoint,application/vnd.ms-excel'
));
if (!empty($attached_documents)):
	echo '<ul>';
		foreach($attached_documents as $attached_document) {
			$document_url   = wp_get_attachment_url($attached_document->ID);
			$document_title = apply_filters('the_title',$attached_document->post_title);

			echo '<li><a href="' . $document_url . '" title="' . $document_title . '" target="_blank">' . $document_title . '</a></li>';
		}
	echo '</ul>';
endif;
?>

This example lists all PDF, Word, PowerPoint and Excel files. For more MIME types, check out w3school’s comprehensive list.

Remove WordPress version from RSS and head tags

By default your WordPress blog is showing which version of WordPress it is running on. This information can be found on these two places:

In a head tag:

<meta name="generator" content="WordPress 2.9.2" />

In a “generator” tag in your RSS feed:

<generator>http://wordpress.org/?v=2.9.2</generator>

To hide this information – just add the following lines to the functions.php file in your theme directory:

<?php
	/* Remove WordPress version */
	remove_action('wp_head', 'wp_generator');

	function remove_feed_generator() {
	return '';
	}
	add_filter('the_generator', 'remove_feed_generator');
?>

Why hide this information? Some versions of WordPress have included vulnerabilities in the past and will most probably do so in the future as well. By hiding your WordPress version you will make it a bit harder for a potential hacker to know which vulnerabilities to use.

Also, remember to keep both your WordPress installation and it’s plugins up-to-date!

Writing your own iframe shortcode plugin for WordPress

When you want simplify publishing of specific elements or code chunks, WordPress Shortcodes might come in handy. Basically it replaces a piece of text that you insert via the editor with something else, defined in your template or in a plugin.

When you want simplify publishing of specific elements or code chunks, WordPress Shortcodes might come in handy. Basically it replaces a piece of text that you insert via the editor with something else, defined in your template or in a plugin.

Here’s an example on how to create a plugin that allows you to insert iframes using shortcodes. Regular iframe tags can be inserted via the HTML editor in WordPress, but the example below will give you a hint on what it can be used for.

<?php
/*
Plugin Name: Iframe Shortcode Plugin
Plugin URI: http://www.guidecloud.com/2010/07/14/writing-your-own-iframe-shortcode-plugin-for-wordpress/
Description: Add iframes to Posts and Pages within WordPress.
Author: GuideCloud.com
Version: 1.0
Author URI: http://www.guidecloud.com/
License: GPL2
*/

class guidecloud_iframe_shortcode {
    function shortcode($atts, $content=null) {
		extract(shortcode_atts(array(
			'url' 	=> '',
			'scrolling' 	=> 'no',
			'width' 	=> '100%',
			'height' 	=> '500',
			'frameborder' 	=> '0',
			'marginheight' 	=> '0',
		), $atts));

		if (empty($url)) return '<!-- Iframe: You did not enter a valid URL -->';

	return '<iframe src="'.$url.'" title="" scrolling="'.$scrolling.'" width="'.$width.'" height="'.$height.'" frameborder="'.$frameborder.'" marginheight="'.$marginheight.'"><a href="'.$url.'" target="_blank">'.$url.'</a></iframe>';
    }
}

add_shortcode('iframe', array('guidecloud_iframe_shortcode', 'shortcode'));
?>

Create a new file called iframe-shortcode.php, paste the code above and upload it to your wp-content/plugins/ directory. Go to “Plugins” in your WordPress administration and activate the plugin.

Once the plugin has been activated you can place iframe shortcodes, like the example below, into your WordPress posts.

[iframe url="http://www.linktoiframe.com/iframepage/" height="500" width="100%" scrolling="no" frameborder="0" marginheight="0"]

You can also download the plugin here:
WordPress Iframe Shortcode Plugin

More reading:

WordPress 3.0 – now available!

One of the most interesting updates of WordPress was launched this evening – WordPress 3.0.

One of the most interesting updates of WordPress was launched this evening – WordPress 3.0.

Among the 1,217 bug fixes and feature enhancements you will find:

  • Custom Post Types – no more need to hack posts or pages into something they’re not
  • Merge between WordPress MU and regular WordPress – now available within the same version. More info here.
  • Custom menus – create your own menu
  • New default theme – Twenty Ten

Introducing WordPress 3.0 “Thelonious”

Thanks to everyone involved – you’ve done an amazing job!

“Installation failed” when upgrading WordPress? Here’s the solution

There are a number of variations on this error message, some more descriptive than others. Here’s one solution…

After a few hours of trying to find a solution to the “Installation failed” error message, when using the automatic upgrade feature in WordPress, I found this thread

There are a number of variations on this error message, some more descriptive than others. This solution will however only work when you just get “Installation failed” as the error – nothing more, nothing less. In this case it was tested on a WordPress 2.8 to WordPress 2.8.4 upgrade with WordPress installed in the website’s root folder.

The solution

The FTP account, used for the automatic upgrades, did in this case have the WordPress installation folder as it’s root folder. By moving the FTP root up one level, above the WordPress installation folder. Example:

FTP root folder – before:
/home/domains/mydomain.com/public_html/

FTP root folder – after:
/home/domains/mydomain.com/

Your web host might be able to help you out if you can’t configure this using your control panel.

Happy upgrading!

How to setup 301 Permanent Redirect on a specific page

Redirect pages or folders to a new location using “301 Permanent Redirect”. Code samples and instructions for ASP.Net, PHP, ASP Classic, Apache .htaccess and Internet Information Server (IIS).

The following instruction will show you how to redirect a specific file on your website to a new location.

When should I use “301 Permanent Redirect”?

HTTP 301 Permanent Redirects should be used when you are about to change page name on a page that has been included in any search engine index. The 301 redirect ensures that search engines and users are directed to the correct page. The HTTP 301 Status Code means that the page has been moved to a new location, permanently.

Permanent Redirects using PHP

Add the following code to your PHP page:

<?php
// Permanent redirection
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.newlink.com/");
exit();
?>

301 Permanent Redirect using ASP.Net

Add the following code to your ASP.Net page:

<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location",http://www.newurl.com/);
}
</script>

Permanent Redirects in ASP Classic (VB)

Add the following code to your ASP page:

<%@ Language=VBScript %>
<%
' Permanent Redirect
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", "http://www.newlink.com/"
Response.End
%>

Redirect a specific page using .htaccess on Apache

If your website is running on an Apache server, you can add your redirects to a file named .htaccess (no file extension). Add the code below using a text editor and upload fhe file to your website’s root directory.

RewriteEngine on
Redirect 301 /oldpagename.html http://www.newlink.com/newpagename.html

Permanent Redirects in Internet Information Server (IIS)

Follow these steps to redirect a specific page or folder to a new location:

  1. Open “Internet Information Services (IIS) Manager”, found under “Start > Control Panel > Administrative Tools”.
  2. Browse to the website and file/folder you would like to redirect
  3. Right click on the file/folder and choose “Properties”
  4. Select the “A redirection to a URL” radiobutton (see screenshot below)
  5. Enter the new URL in the “Redirect to:” field
  6. Check the “A permanent redirection for this resource” checkbox
  7. Click on “Apply”

Configure

More information

HTTP Status Code Definitions
HTTP 301 on Wikipedia
List of HTTP status codes on Wikipedia
301 redirects on Google Webmasters Help