Tips & Tricks
Adding a favicon to your site
Looking to add a favicon to you site?
Inside your WordPress theme’s functions file (functions.php
) add the following to inside your PHP
code.
/** * FAVICON * @WPCult.com */ function my_favicon() { ?> <link rel="shortcut icon" href="<?php echo bloginfo("stylesheet_directory") ?>'/images/favicon.ico" /> <?php } add_action('wp_head', 'my_favicon');
That’s it, just be sure to upload an icon image or a .gif/.png
. Be sure to correct the target location id the file is located somewhere else.
Tips & Tricks
Remove spaces when echoing the_title
Ever wanted to print or echo the WordPress title attribute without spaces?
This little trick can be useful for calling custom functions and printing the title with out spaces for W3C compatibility. I used this trick in a new theme called Galleria, which will be out for public download in the coming days.
Using this comes in handy for a delicious text link:
<?php $title = get_the_title(); ?> <a href="http://del.icio.us/post?url=<?php echo $title; ?>&<?php echo str_replace(" ", "%20", $title); ?>"> Bookmark This (<?php echo $title; ?>)</a>
What I am doing is calling $title = get_the_title();
and using str_replace(" ", "%20", $title);
to replace empty spaces with a %20
, which is used in URL encoding empty spaces.
Alternatively you can use a dash or underscore.
Thanks to Jason Boyle for his adaption.
Tips & Tricks
Display the_excerpt only if there is text
Have you ever wanted to display the excerpt only if you write one? A simple couple lines of code can display the_excerpt
any where you like.
In my new theme, I am using this coded trick to display the excerpt on a single post only if I’ve got text inside. Usually if you use the_excerpt
and you don’t have one, it will fake one for you.
This is not something that I wanted to do on the single post page. So I used the following code to check if the excerpt existed.
if ( !empty( $post->post_excerpt ) ) :
Once this action is taken into account, you can factor in what code you want to out put if the post_excerpt
isn’t empty.
if ( !empty( $post->post_excerpt ) ) : the_excerpt(); else : false; endif;
The above code checks if there is an excerpt and print’s it to the screen. If there isn’t an except, it doesn’t do anything.
Tips & Tricks
Add a shortcode
This is a simple one.
/** * Your Blog title * */ function my_blog_title() { $blogname = get_bloginfo('name'); return '<span class="blog-title">' . $blogname . '</span>'; } add_shortcode('blog-title', 'my_blog_title');
Just add this to your functions.php file and then add [blog-title] in any post or page and it will return your Blog Title. :)
-
Tips & Tricks7 months ago
WordPress Security Hacks
-
Pages2 months ago
Write For Us – Guest Post
-
Showcase2 months ago
StylizedWeb.com
-
News2 months ago
How to: Show/Hide any div box with jQuery in WordPress
-
Tips & Tricks4 weeks ago
Remove the title attribute using jQuery
-
Tips & Tricks6 months ago
How to: show/hide a widget in WordPress with jQuery
-
Plugins6 months ago
Top Membership plugins
-
Tips & Tricks2 months ago
Limit the characters that display on the_title
Peter
April 2, 2009 at 11:37 pm
The backstory on why it’s traditionally a .ico (instead of .gif or .jpg) is actually pretty interesting – you can read up on it on this wikipedia entry:
http://en.wikipedia.org/wiki/Favicon
Ok, so maybe its only interesting to me :).
Peter´s last blog post..Creating User Friendly Custom Fields by Modifying the Post Page
Austin
April 3, 2009 at 10:00 am
Yeah, I’ve read it. Though with more browsers supporting it, I typically like to use transparent png’s these days.
Pingback: Tip: Favicon Function « WP TOY
Pingback: WordPress articles for 03.04.09 | WPStart.org - WordPress themes, plugins and news
Searchgo
April 18, 2009 at 1:24 pm
Thanks great post.
Matthew Coleman
April 27, 2009 at 1:17 pm
Is there a benefit to doing it this way, instead of just adding into the header.php?
Austin
April 27, 2009 at 2:06 pm
No difference.
mktanny
October 29, 2009 at 4:13 pm
Moved from blogspot to wordpress and then was searchinhg for a way to add favicon to my blog then got here thnx.
How To Add Favicon To Your Blogspot Blog