Category Dropdown

WordPress has a built-in display categories widget that can show as a list or a dropdown. However, it only shows categories with posts attached to them. If you want to show all categories in a dropdown use this code. <form action=”<?php bloginfo(‘url’); ?>/” method=”get”> <?php $select = wp_dropdown_categories(‘show_option_none=Select State&show_count=1&orderby=name&echo=0&selected=0&hide_empty=0’); $select = preg_replace(“#<select([^>]*)>#”, “<select$1 onchange=’return this.form.submit()’>”, Read More…

Google Analytics Async Event Tracking

Trying to figure out how to get event tracking working with the new async (analytics.js) code was a pain. Googles documentation for anything to do with analytics is always confusing. <script> (function(i,s,o,g,r,a,m){i[‘GoogleAnalyticsObject’]=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,’script’,’//www.google-analytics.com/analytics.js’,’ga’); ga(‘create’, ‘UA-XXX-X’, ‘example.com’); ga(‘send’, ‘pageview’); //here is the code that actually worked. You put it in the script area Read More…

Custom WordPress Redirect on Login Fail

I use this snippet to change the default redirect to /wp-login when user authentication fails on attempted login.   //redirects user to the page the login form is on and adds ?login=failed to the url add_action( ‘wp_login_failed’, ‘my_front_end_login_fail’ ); // hook failed login //redirect on login fail (doesn’t work when user clicks empty form. The Read More…

Query posts get post data

You can use this to access the the WordPress posts.  //Reading posts for “Events” category;     $posts = get_posts(“category=” . get_cat_ID(“Events”) .’&orderby=date&order=ASC&numberposts=50′); Then you can create an array and access the post data like this. //Creating drop down item array.     $items = array();     //Adding initial blank value, for a dropdown, or just to Read More…

WordPress Comments

If you want to modify how the comments # is displayed you can use this code: <?php if ( comments_open() ) : ?> <span class=”post-comment”><?php comments_popup_link( __( ‘Comments <span>0</span>’, ‘base’ ), __( ‘Comments <span>1</span>’, ‘base’ ), __( ‘Comments <span>%</span>’, ‘base’ ) ); ?></span> <?php endif; //post comment ?> As you can see you can add Read More…

Redirects

As far as I can tell all redirect calls need to happen before the <?php header(); ?> code is called. I will have to test it more to know for sure.