I'm trying to return the child theme url for a child theme favicon. The official code to use in this case is:

//* Display a custom favicon
add_filter( 'genesis_pre_load_favicon', 'sp_favicon_filter' );
function sp_favicon_filter( $favicon_url ) {
    return 'http://www.mydomain.com/wp-content/images/favicon.ico';

but adding absolute urls stresses me out ;)

I know that


returns the correct url, so how do I get that into the 'return'?

I've tried

add_filter( 'genesis_pre_load_favicon', 'bg_favicon_filter' );
function bg_favicon_filter( $favicon_url ) {
    $stylesheet_dir_uri = get_bloginfo('stylesheet_directory');
    $stylesheet_uri = $stylesheet_dir_uri . "/images/favicon.ico";
    return  '$stylesheet_dir';

but I'm out my depth here

Any suggestions?

  • 1
    Why are you putting apostrophe in return statement? – Nilambar Sharma Nov 11 '14 at 4:40
  • because I'm still learning, sorry - it was a mistake, I'll do better next time I promise ;) – morktron Nov 12 '14 at 9:28

The correct function to use here is get_stylesheet_directory_uri(). Please feel free to read this useful post by @ChipBennet regarding this issue

Your use of syntax is also wrong in your return statement as already pointed out. A variable is php, not html, therefore you don't need the single quotes which are used to wrap html in a mixed string.

You can simply just use the following as your return statement

return get_stylesheet_directory_uri() . '/images/favicon.ico';
  • Excellent thanks Pieter, that is perfect, you are a legend :). Thanks also for explaining my syntax error, it's very helpfull – morktron Nov 12 '14 at 9:31
  • My pleasure, glad it helped. Enjoy :-) – Pieter Goosen Nov 12 '14 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.