Web Design category archive

Remove title attributes from WordPress menu wp_nav_menu

If you’re reading this then you are looking for a solution to remove those annoying title attributes from menus generated by WordPress built-in functions wp_nav_menu(), wp_page_menu(), wp_list_categories(). Some might argue against removing those because of the accessibility issues it might introduce, but in most cases those annoying tooltips that are being displayed by browsers when the title attribute is found usually look rather bad and we want to keep out navigation clean, don’t we?

The solution is quite simple. We will utilize regular expressions to do that. Don’t worry if you’re not familiar with them, just follow instructions below and it will work.

Simply edit your theme’s functions.php and add the code below to it

function remove_title_attr( $nav )
{
return $nav = preg_replace('/ title=\"(.*?)\"/', '', $nav );
}

add_filter( 'wp_nav_menu', 'remove_title_attre' );
add_filter( 'wp_page_menu', 'remove_title_attr' );
add_filter( 'wp_list_categories', 'remove_title_attr' );

You don’t have to add filters to all of the functions, just leave one/ones you use.

Free pixel media player icons

Everyone likes free stuff so here’s little something for you all. It’s a pack of pixel icons to use in your projects. They are of various sizes from 4px to 11px and available in PSD, PNG, FLA (CS4) and SWF formats.

Have fun.

free-pixel-media-player-icons

Download

Remove HTML links in WordPress post comments

Here’s a quick tip on how to remove those nasty spammy HTML links that people leave in your blog comments. Don’t get me wrong, there’s nothing bad in having links in comments but there’re many people who abuse this feature nowadays to create backlinks to their sites, leaving silly comments like “Hey your blog is awesome! Check out my “castration kits” website” or something stupid like that.

This can get really annoying so if you want to remove links in your WordPress comments all you need to do actually is to include this little bit of code in your theme’s functions.php file.

remove_filter('comment_text', 'make_clickable', 9);

That’s it. Save the file and upload it to your theme’s folder. You now won’t see any links in your blog comments. Enjoy spam free blogging.

How to remove title attributes from the WordPress page list

If you work with WordPress then must have noticed that the function wp_list_pages generates a list where each element gets a title attribute added automatically. This isn’t bad but most browsers will try helping us showing a small tolltip when we hover the mouse over the link and we designers don’t want that kind of behaviour.

To solve this problem we will require some help or regular expressions. If you don’t know what they are don’t worry, simply use the code and see it doing its magic.

$pages= wp_list_pages("echo=0&title_li=");
$pages= preg_replace('/title=\"(.*?)\"/','',$pages);

The second line is the one that does the trick. It strips title attributes and leeps our list tidy.

Hope you find it useful.

How to get top-level page in WordPress

February 28th, 2011 Web Design, Web Development, Wordpress

Sometimes in WordPress you need to find the name or ID of the top-level page or post. This is actually pretty easy.

$parents = array_reverse(get_post_ancestors($post->ID));
$firstparent = get_page($parents[0]);
echo $firstparent->post_name;
echo $firstparent->ID;

Hope this helps.