quick tips

  • Fix wp_nav_menu on Custom Type Archives in WordPress

    Recently I was working with an issue in WordPress where the site’s menu was not showing up on an archive page for one of my custom post types. There were a few troubleshooting things I tried, including the most common recommendation, use theme_location instead of menu when referencing the menu in your theme (code after the jump):

    (more…)

  • Quick Tip: Turn off Amazon Wishlist Spoilers

    While talking to my mother, whom I sent my Amazon Wishlist to for gift ideas, she told me to not check Amazon until Christmas because she bought stuff off of my list and didn’t want me to see what she got. Luckily, Amazon has thought of this, and there is a really simple way to make sure that you don’t see when people buy things off your list.

    1. Go to your Amazon Wish List.
    2. In the List Actions drop-down (towards the top of the list, on the right), click Update list profile.
    3. Check  “Don’t spoil my surprises.”
    4. Click Save.

    That’s it! You can now view your list without worry of spoilers.

  • Quick Tip: Check to See if a Slug Exists in WordPress

    Recently I was doing some work where I was importing RSS entries into a Custom Post Type in WordPress. Since there were no common IDs between the feed and WordPress, to prevent duplicate entries I tried comparing titles. This also proved to be an issue as titles aren’t always unique, and they weren’t in this case. I settled on comparing slugs; WordPress creates a unique slug for each post from the title, and there’s a way to know what that slug is going to be before the post is added.

    (more…)

  • Quick Tip: Use Post or Page Slug as CSS Class in WordPress

    I don’t know why, but for some reason, I thought WordPress already included the slug of a post or page in either the function body_class() or post_class(). Doing some work over this weekend I realized that’s not the case, but luckily, it’s very easy to do.

    The functions body_class() and post_class() serve as a way for you to easily customize a page’s CSS based on attributes of the page being viewed. They will output things like the post ID, the custom post type, if the page is the blog, home, or front page, and more. One thing it does not include, however, is the post slug. This could be useful if you want to style each of your posts a certain way, or in a more likely scenario, style each page a certain way. If you want to do this, the code is fairly straight forward; both functions accept an option argument: a string of your own classes. We use that combine with the $post array, like so:

    <?php body_class($post->post_name); ?>

    or, if you want to do it on a post-by-post basis:

    <?php post_class($post->post_name); ?>

    Note the latter must be used inside the Loop. Using this, if you have a page named, “Services” with the slug services, the output would look something like this:

    <body class="page page-id-108 page-parent page-template-default services">

    Now you can use the .services (or whatever) class name to do some custom stuff instead of needing to know the page or post ID.