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());
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.
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.
7