
I searched for some instructions on how to easily find dead links on my blog. I found some plugins that do just that but instead of using a plugin to do it why not use this cool method that can also provide you with a custom 404 page ?
The WordPress Codex directory is way cool and it is maybe one of the best wordpress resources out there. Here’s the link that interests us in particular: Creating an Error 404 Page. You just need to create a 404.php file in your theme directory (in case you don’t already have one). Put the following code in it and customize aiding yourself with the comments:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
| <?php get_header(); ?>
<div id="post-entry">
<h1>Whoops !</h1>
<div class="post-content">
<p>You
<?php
#some variables for the script to use
#if you have some reason to change these, do. but wordpress can handle it
$adminemail = get_bloginfo('admin_email'); #the administrator email address, according to wordpress
$website = get_bloginfo('url'); #gets your blog's url from wordpress
$websitename = get_bloginfo('name'); #sets the blog's name, according to wordpress
if (!isset($_SERVER['HTTP_REFERER'])) {
#politely blames the user for all the problems they caused
echo "tried going to "; #starts assembling an output paragraph
$casemessage = "All is not lost!";
} elseif (isset($_SERVER['HTTP_REFERER'])) {
#this will help the user find what they want, and email me of a bad link
echo "clicked a link to"; #now the message says You clicked a link to...
#setup a message to be sent to me
$failuremess = "A user tried to go to $website"
.$_SERVER['REQUEST_URI']." and received a 404 (page not found) error. ";
$failuremess .= "It wasn't their fault, so try fixing it.
They came from ".$_SERVER['HTTP_REFERER'];
mail($adminemail, "Bad Link To ".$_SERVER['REQUEST_URI'],
$failuremess, "From: $websitename <noreply@$website>"); #email you about problem
$casemessage = "An administrator has been emailed
about this problem, too.";#set a friendly message
}
echo " ".$website.$_SERVER['REQUEST_URI']; ?>
and it doesn't exist. <?php echo $casemessage; ?> You can click back
and try again or try using the search box in the sidebar.
</p>
</div>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?> |
Easy enough ? I think it is an awesome method. At least for testing if not for permanent use. Hope this helps. Oh, and by the way, if you have a large blog be ready to be bombarded with emails generated from this 404 page.
Save your code snippets with Snippely
I am currently waiting for FeedReader to finish downloading some enclosures from a feed I am subscribed to. In the meanwhile I though it would be nice letting you know what a great tool Snippely is. Though it is in its developing stage it comes handy for all developers, designers, etc. out there that have a piece of code and want to store it somewhere so that it will be accessible later when needed. It is incredibly simple and straight forward: it lets you create some groups and in those groups you can add snippets. A snippet will have two main parts: the actual code and the note. It has a built in feature for applying different syntax highlighting for PHP, CSS, Ruby and JavaScript. So, as I said it is pretty straight forward and due to its minimalistic interface looks quite nice.
However, it misses a search function, as well as a import/export option. Of course it would have been awesome for it to be able to store the snippets on the web so that they would be accessible for you by using an account or such. Unfortunately it lacks the HTML syntax coloring. Of course there is a lot of work on it still but thankfully it is out there for us to enjoy so let’s be patient with the developers.
Oh, and by the way, to make up for that import/export thing you could do it manually by following the path to the SQLite database file:
“C:\Users\Username\AppData\Roaming\com.snippely.xxx\Local Store\application.db”. And there you have it; you can now be assured that your precious snippets won’t be lost if you decide to work on another computer or any other scenario.
Here are some screenshots to help you make an impression:
Download: http://code.google.com/p/snippely/downloads/list