Search

Posts Tagged ‘WordPress’

How to Customize “Howdy” In WordPress Admin Bar [Quick Tip]

Every WordPress user should be familiar with the “Howdy” message that appears in the Admin Bar when they are logged in. The problem with “Howdy” is that it’s an informal word and sounds very unprofessional. Perhaps for some reason your client is given access to your WordPress Dashboard. If that’s the case, you might want to change it into a more proper greeting like “Welcome” for example.

In this post, we will cover how to do so. To top it off, we’ll also show you how to display a customized greeting for special public holidays like Christmas and New Year. If this sounds like an idea you have been wanting to execute for awhile now, let’s check out how it’s done.

Overwrite the “Howdy” Message

First, we want to overwrite the “Howdy”. Add these lines in the functions.php of your theme.

 function howdy_message($translated_text, $text, $domain) { $new_message = str_replace('Howdy', 'Welcome', $text); return $new_message; } add_filter('gettext', 'howdy_message', 10, 3); 

The above function replaces the “Howdy” with “Welcome” using the PHP str_replace function and applies the function through the WordPress own gettext filter. Once added, refresh the WordPress Dashboard and the greeting should now say “Welcome”, as shown below.

Special Holiday Greeting

Now we can make the greeting message more personalized. The idea is to greet the user during the holiday season. For example, if today was New Year, we would like to display Happy New Year followed by the user name. Likewise, if it were Christmas, we could wish the user with a Christmas greeting.

We need to get the month and the date. In PHP we can use date() function to retrieve the current date and month. Create a new function to call date() and output the result, like so.

 function public_holiday() { $date = date('d-m'); } 

Assuming that today is 9th September, the output of this function would be 22-09. That is also to say that 01-01 is New Year, while 25-12 is Christmas. Having retrieved the date we can utilize it to set the greeting message, like so.

 function public_holiday() { $date = date('d-m'); switch($date) { case '01-01': $message = 'Happy New Years'; break; case '25-12': $message = 'Merry Christmas'; break; default: $message = 'Welcome'; } return $message; } 

As you can see above, we also set the default message to “Welcome” when the return value of the $date does not fall to ’01-01′ or ’25-12′.

Now, we need to slightly change our previous function in order to show the message, like so.

 function howdy_message($translated_text, $text, $domain) { $message = public_holiday(); $new_message = str_replace('Howdy', $message, $text); return $new_message; } add_filter('gettext', 'howdy_message', 10, 3); 

Refresh the WordPress Dashboard once again. And if it is New Year or Christmas you should see the Howdy message change into what you’ve specified as per below.

More Ideas

There are more cool ideas that we can achieve. Some examples of what you can do to improve this particular area of WordPress includes adding more special holiday greetings like for Eid or by displaying a localized greeting based on the users’ current location or language preference. All you need is some creativity and basic understanding on PHP and WordPress functions, classes, and hooks.








65 Amazing WordPress Photography Themes on the Market This Month

WordPress is an excellent content management system for photographers, in part because there are so many outstanding themes available, both free and premium. With so many quality themes/templates…



Click through to read the rest of the story on the Vandelay Design Blog.

65 Amazing WordPress Photography Themes on the Market This Month

WordPress is an excellent content management system for photographers, in part because there are so many outstanding themes available, both free and premium. With so many quality themes/templates…



Click through to read the rest of the story on the Vandelay Design Blog.

How to Register Custom Taxonomy For WordPress Users [WordPress Tip]

The Custom Taxonomy feature has been introduced since WordPress 2.9. It allows you to create custom groups for Post, Page as well as Custom Post Types.

Say that you are building a book directory website, and you have created a Custom Post Type for posting the Books. By using Custom Taxonomy, you can create a custom taxonomy for it, called Genre. Within this Genre taxonomy, you can create a number of items (which technically is called terms) such as Fiction, Kids, or Biography for grouping the Books.

Unfortunately, at this point, we can’t register Custom Taxonomy to Users; at least not in a straightforward way as we would register it in the other Post Types. One perfect application that we could foresee from this idea is that we can use it to assign additional user attributes, such as their occupation, profession or organizational position, in place of registering a new set of User Roles. It also opens the possibility to query the users based upon the assigned taxonomy terms.

If this idea is something that may benefit your website, take a look at this tip.

Getting Started

First, we will install a plugin named User Taxonomies to simplify our job.

Once the plugin is activated. Go to GenerateWP to generate the Taxonomy codes. Put the code output in the functions.php file of your theme. This code snippet below is an example. Though, it has been stripped out to make this article look shorter. You can follow this link to see the full code.

 if ( ! function_exists( 'user_staff_position' ) ) { function user_staff_position() { register_taxonomy( 'staff_position', 'post', $args ); } add_action( 'init', 'user_staff_position', 0 ); } 

Now, change the Post Type parameter in the following line:

 register_taxonomy( 'staff_position', 'post', $args ); 

…from post to user, like so:

 register_taxonomy( 'staff_position', 'user', $args ); 

Now, go to the WP-Admin, and you should find a new menu added under the Users menu, as seen below.

Assigning the Custom Taxonomy

Navigate to the new menu and create a few terms. For this example, we created two items: CEO and Managers.

Then go to user editing screen and assign one item from the taxonomy to the user.

Query the Users

We are going to display the users in the theme based on the given term (of the taxonomy). But before going further, let’s create a new page template. We are going add the codes throughout the following section within this new template.

In this particular case, we won’t be able to query the users with get_users or WP_User_Query; when you create a new WP_User_Query class, it does not output the Custom Taxonomy that is assigned to the users. Justin Tadlock, in his tutorial, shows us how to use the get_objects_in_term function, instead.

This function outputs the object ID (which in our case the object means the user) that are tied with the term. To use it, we need two parameters: the Term ID and the Taxonomy name. You can spot the Term ID at the Browser URL bar when you edit it as shown below.

Once you’ve found the ID, put it within the function, like so.

 $users = get_objects_in_term(3, 'user_position'); 

You can use var_dump() to display the object IDs that have been retrieved; In my case, it returns the users with the ID of 1 and 3.

Using these IDs, we can also retrieve, for example, the user name and avatar.

 <ul> <?php if ( !empty( $users ) ) : ?> <?php foreach ( $users as $id ) : ?> <li class="user-entry"> <figure><?php echo get_avatar( get_the_author_meta('email', $id), '40' ); ?></figure> <h4 class="user-title"><a href="<?php echo esc_url( get_author_posts_url( $id ) ); ?>"><?php the_author_meta( 'display_name', $id ); ?></a></h4> </li> <?php endforeach; ?> <?php endif; ?> </ul> 

…and, finally, here is the result.

That’s it. You can freely modify the above codes to meet your requirement.








Top 50 Best Responsive WordPress Portfolio Themes

If you’re looking for a portfolio template to showcase your art, photography, or web design Singapore work, the wide selection of quality themes makes WordPress a great option. While there have been many…



Click through to read the rest of the story on the Vandelay Design Blog.