Mar 03

Sample 404 Error Image

If you attempt to access the URL of a non-existent image file on a website – say a jpg, png or gif file – you will usually be redirected to the 404 error page. If the image is embedded via an HTML img tag, this will normally result in your browser displaying a missing image icon.

Instead, we can handle this in a more elegant way by creating a special 404 Error image which will be returned when someone attempts to request a non-existent image file on your website.

All we have to do is:
Continue reading »

Tags:

Mar 03

This snippet of PHP code takes any shortened URL, like those from Bitly, Google or Twitter, and expands it into the full and final destination URL.

function expandShortUrl($url)
{
	$headers = get_headers($url, 1);

	$loc = $headers['Location'];
	if(is_array($loc))
	{
		// get the highest numeric index
		$key = max(array_keys( $loc));
		return $loc[$key];
	}
	else
	{
		return $loc;
	}
}

Hat Tip: Deluxe Blog Tips and Karl Groves – Easily Expand Short URL Using PHP

Tags: ,

Mar 03

This piece of code will allow any user with the capability of ‘moderate_comments’, to include a shortcode within a post comment. If the user does not have this permission, any shortcodes will be displayed as normal text. The code should be placed inside your theme’s functions.php file.

This is useful when combined with affiliate marketing plugins that allow you to display a clickable ad using a shortcode. A visitor to your site might post a comment on an article, requesting a recommendation for a product. You can then reply to their comment, and include a affiliate link or banner ad that advertises the product in question.

For example, you may post an article about Tennis, and a user may request a recommendation for a suitable tennis racket. You can then reply with a recommendation for a racket, with an advertisement for that racket that any user who reads that ad may decide to click.

function filterComments($comments)
{
	$filtered_comments = array();
	foreach ($comments as $comment)
	{
		// if not registered
		if ($comment->user_id == 0)
		{
			$filtered_comments[] = $comment;
		}
		else
		{
			$comment_author = new WP_User($comment->user_id);
			// if has capability 'moderate_comments'
			if ($comment_author->has_cap('moderate_comments'))
			{
				$comment->comment_content = do_shortcode($comment->comment_content);
				$filtered_comments[] = $comment;
			}
			else
			{
				$filtered_comments[] = $comment;
			}
		}
	}
	return $filtered_comments;
}

add_filter( 'comments_array', 'filterComments' );
Mar 01
  • AussieWPExpert: WordPress plugin Color Scheme every Theme lets you change the colours of any theme via the theme customizer: http://t.co/ct0ob19JUj
  • AussieWPExpert: How to test which of the WordPress Jetpack plugin's modules are enabled using PHP code: http://t.co/BCxyryHAmM
  • AussieWPExpert: How to set up numbered page navigation in the WordPress Thesis theme version 1.x: http://t.co/4jyzA3C3re
  • AussieWPExpert: WordPress plugin Conversation Starter increases user participation by prompting them to answer questions in the post: http://t.co/IldevW9LCc
  • AussieWPExpert: WordPress plugin "Where did they go from here" show what else readers who viewed a page also viewed on the site – http://t.co/zU8KXfytGA
  • AussieWPExpert: WP Author Slug plugin improves WordPress security by preventing login names from appearing in the author archive URL: http://t.co/nX6TbgacSP
  • AussieWPExpert: WordPress plugin Simple Pagination lets you set up advanced pagination for posts and comments, with 6 stylesheets: http://t.co/my5QIfrUPA
  • AussieWPExpert: WP-AutoSharePost plugin automatically shares WordPress posts on facebook/twitter and scrapes the facebook comments: http://t.co/bBlAMBtgEf
  • AussieWPExpert: plugin Really Static creates static html files from your WordPress blog whenever a post/comment is published/edited: http://t.co/whpatQXa24
  • AussieWPExpert: WordPress plugin Real IP 4 Comments corrects post commenters' IP addresses when they are accessing behind a proxy – http://t.co/Zlgu1d427U
  • AussieWPExpert: Plugin lets you publish/embed your Tweets to your WordPress blog automatically or manually with a single click – http://t.co/4qR36sfmFx
  • AussieWPExpert: WPExplorer: My Useful WordPress Snippets List By Remi Corson – http://t.co/pVTW78urvA
  • AussieWPExpert: WP Page Widget lets you customise the widgets displayed for each WordPress page, post and custom post type – http://t.co/ujGAouGBCZ
  • AussieWPExpert: Brief Blogs for Week Ending February 22, 2013 http://t.co/6dep2uABxA

css.php