Get Post Slug in WordPress

7

By : Josh Stauffer

I needed to get just the post slug for a project I have been working on. I found several sites that had similar ways of getting the post slug but I came up with an approach that utilizes WordPress’ get_permalink() and PHP’s basename().

The common approach:


$post_obj = $wp_query->get_queried_object();
$post_ID = $post_obj->ID;
$post_title = $post_obj->post_title;
$post_slug = $post_obj->post_name;

My approach:


$slug = basename(get_permalink());

8 Slam Dunks Gone Bad

3

By : Josh Stauffer

Watch this collection of slam dunks that ended terribly wrong. Some will make you laugh and some will make you hurt.

  1. This kid launches off the trampoline and makes the dunk but gets his leg caught in the rim.
  2. This guy tried to jump over a girl and dunk the ball but instead he plows her over and misses the dunk.
  3. This dude dunks the ball, then shows off a bit, and finally gets stuck in the rim.
  4. Guy jumps off of trampoline for the dunk but collides with the backboard instead.
  5. This guy downs a beer, circles a bat, then attempts the dunk but instead he pounds himself into the driveway.
  6. Guy tries a double front flip dunk and collides with the rim.
  7. This guy gets his hand caught in the net and falls to the ground.
  8. Another trampoline dunker doing some front flips and gets leg caught in rim.

Free Silhouette Images

0

By : Josh Stauffer

There have been several times in the past that I can remember designing something and thinking that using a silhouette image would be cool. I often abandon this idea because I can never find what I am looking for and for the price that I want it… FREE.

Finding free silhouette images just became a little easier. I now have “85 Free High Quality Silhouette Sets” to choose from, thanks to Hongkiat.

Track 404s with Google Analytics

0

By : Josh Stauffer

Tracking 404 pages with Google Analytics is extremely simple. If you have a custom 404 page to handle your 404 pages, you just need to make a simple change in your GA tracking code.

Change this line of code:

pageTracker._trackPageview();

To this:

pageTracker._trackPageview("/404.html?page=" + document.location.pathname + document.location.search + "&from=" + document.referrer);

So the final GA tracking code for your 404 page should look like this:

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-xxxxxxx-x");
pageTracker._trackPageview("/404.html?page=" + document.location.pathname + document.location.search + "&from=" + document.referrer);
} catch(err) {}
</script>

That’s all there is to it. However, for my purposes I am wanting to use this Analytics code with WordPress. I usually just insert my Analytics code before the closing </body> in my theme’s footer.php file. Since this technique for tracking 404s requires slightly different code than the standard GA tracking code, you can use PHP and the WordPress is_404() function to display the correct code. Just paste this code into your theme’s footer.php file:

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-xxxxxxx-x");
<?php if ( is_404() ) { ?>
pageTracker._trackPageview("/404.html?page=" + document.location.pathname + document.location.search + "&from=" + document.referrer);
<?php } else { ?>
pageTracker._trackPageview();
<?php } ?>
} catch(err) {}
</script>

Please remember to use your Analytics Account ID and not UA-xxxxxxx-x.