WordPress: Remove Date From Posts on Category Page

The first thing you will need in order to remove the date from category pages is the id of the category which you wish to hide the dates on. To get the id click on ‘Categories’ in the admin and then click on the actual category you wish to affect. In the url you will see the id, similar to this:

In this instance, our ID is ’42’. Next you will need to find the file that you need to add the code into. By default WordPress will look in

\wp-content\themes\'your-theme'\

for the file in this order:

  1. category-slug.php (Note: available with Version 2.9)
  2. category-ID.php
  3. category.php
  4. archive.php
  5. index.php

Once you have found the appropriate file modify it like so around line 53 near the h2 tag:

<?php //hide date for category
	$show_date=true;
	$cat_array =  get_the_category($post->ID); 
	//print_r($cat_array);	
	$count = count($cat_array);
        for($i=0 ; $i < $count; $i++){
            $cat_id = $cat_array[$i]->cat_ID;
	    if ($cat_id == 42){
	        $show_date = false;
	    }
        }
if ($show_date) {?>
<span class="date"><?php the_time('d M'); ?></span>
<?php
}
?>

Be sure to replace the number on this line

 if ($cat_id == 42)

with this ID from above.
If you wish to hide the date on individual posts, you can add the same code to ‘single.php’

Blank html template – Transitional dtd

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 
<head>
 
<title>HTML Template</title>
 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<!--link type="text/css" rel="stylesheet" href="style.css"-->
 
</head>
 
<body>
 
</body>
</html>

Download zipped html file

Detect Adblock Users on a WordPress Blog

The following code allows you to display an alternate message for your advertisements to users who are using Adblock as well as most other modern online advertisement blocking applications.
adblockplus
In your blog’s root directory (folder containing the wp-addon, wp-content and wp-includes sub folders), create a file and name it “adframe.js”.

This name is crucial because most ad blockers will prevent files with this name from being accessed by the browser.  In the file you have just created insert the following code:

adblock = false;

Now go to where you have added the advertisements in your code.  For instance, if you’re running Google Ads, it would look something like this:

<script type="text/javascript"><!--
google_ad_client = "pub-xxxxxxxxxxxxxxxxx";

Just before “<script” add the following div tag:

<div class=”a”>

After the second “</script>” tag, add the closing div tag “</div>”

The last thing to do is add the javascript logic that decides if we should display the alternate message.  Add this just before the closing body “</body>” tag:

<script type="text/javascript">
<!--
 var adblock = true;
//-->
</script>
<script type="text/javascript" src="http://<your-blog-domain>/blog/adframe.js"></script>
<script type="text/javascript">
<!--
 if(adblock) {
 var allElements = document.getElementsByTagName('div');
 for (var i = 0; i < allElements.length; i++) {
 if (allElements[i].className == 'a') {
 allElements[i].innerHTML = 'Hello, you are blocking ads.';
 }
 }
 }
</script>

Be sure to replace “<your-blog-domain>” with your own as appropriate.

Users running ablocking software will see the following message ‘Hello, you are blocking ads’.  Of course you can substitute this message with anything you want, or even add some html.  I should note that this is a prickly issue with valid points for and against ‘blocking the blockers’.  I found an excellent example of the central arguement anonymous user “Headz” posted on another site.

>>It’s their connection. Their experience.

“You’re not entitled to your own person experience when visiting a website, anymore than when visiting a McDonald’s, or your local bank. If you walk into a McDonald’s, and there’s a huge annoying neon sign promoting some burger, you don’t have the right to tear it down to better accommodate your dining experience. It’s the restaurant owner’s prerogative to structure his business how he or she chooses, which may include big annoying signs. If you don’t like it, you have other dining options — Like the Burger King across the street.

If you don’t like that your favorite tech site is flooded with ads, then go somewhere else. You have other tech site options. It’s arrogant to think you have a right to tear someone’s business apart to better accommodate your personal experience. You wouldn’t do it at a McDonald’s, so I don’t understand how you feel justified doing it at a website.”

Of course, his argument fails to consider the differences between brick-and-mortars and electronic venues.  I’m not sure which side I’m on for this one, I’ve already flip-flopped twice.  Thanks to http://detect-ad-blocking-software.webconrad.com/ for the original code snippet.

Create Blank Page for WordPress Blog Using Your Theme Template

There may come a time when you need to create a blank page on your WordPress site that still uses your template’s header, footer and sidebar.  For example, if you incorporate your own custom search from google, you will need to specify a landing page where the search results will be displayed.

You could use WordPress to create a new page, but this has some problems.wordpress logo

  • WordPress tends to add code to the page the you don’t need or want
  • You will need to recreate this file whenever you switch themes or upgrade.
  • You cannot easily control where this file is created.

To avoid these problems we can use some built-in functions to display a blank page that uses your template and gives you greater control of the page’s content.

First, create a new file in the root directory of your blog (the directory that contains ‘wp-blog-header.php’).  Name it whatever makes sense to you but make sure to give it the ‘.php’ extension.  Copy the following into the file you have just created:

Hello!

;
 
<!--?php 
get_footer();
?-->

You can see an example of this page here – http://joe-riggs.com/blog/blank.php.  You can add any valid html or javascript to the section between the php tags and will be displayed.  If you don’t want to display the header, sidebar or footer you can simply comment out or remove that particular line – ie : delete entire  “get_sidebar();” line to remove the sidebar.