Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

How can I set the SRC URL of the custom logo image?

If you set your logo in the customizer and your theme is using the_custom_logo() or get_theme_logo() to display the logo, then you can use the wp_get_attachment_image_attributes and check if the class is “custom-logo”. If it is, then change the src attribute to wherever you want. You’ll have to still set the logo in the customizer.

namespace StackExchange\WordPress;
function imageAtts( array $attr, \WP_Post $attachment, $size ) : array {
  if( 'custom-logo' === $attr[ 'class' ] ) {
    $attr[ 'src' ] = 'https://example.com/logo.jpg';
  }
  return $attr;
}
\add_filter( 'wp_get_attachment_image_attributes', __NAMESPACE__ . '\imageAtts', 10, 3 );

If you don’t want the extra step of setting the logo in the customizer, you can use the get_custom_logo filter.

namespace StackExchange\WordPress;
function imageAtts( string $html, int $blog_id ) : string {
  return sprintf(
    '<a href="https://wordpress.stackexchange.com/questions/292389/%1$s" class="custom-logo-link" rel="home" itemprop="url">%2$s</a>',
        \esc_url( home_url( "https://wordpress.stackexchange.com/" ) ),
        'https://example.com/logo.jpg'     
  );
}
\add_filter( 'get_custom_logo', __NAMESPACE__ . '\getCustomLogo', 10, 2 );

Either way, in the code for your theme, use the_custom_logo() to display the logo.

Related Posts:

  1. What’s the difference between home_url() and site_url()
  2. Prevent “main” WPMU site_url() being returned in functions
  3. Custom page with variables in url. Nice url with add_rewrite_rule
  4. Is it possible to use a forgot password url filter?
  5. Create Custom URL structure for specific Post category
  6. How can I rename the WordPress AJAX URL? [duplicate]
  7. Changing itemprop from logo to image on custom logo?
  8. Custom logo sizes for multiple logos
  9. Ninja form Redirect depending on text field content [closed]
  10. wp-comment author- url +, email filter hook
  11. Removing custom meta data
  12. WordPress on AWS Auto scaling and ELB giving 503
  13. WordPress converts media extention URL automatically to video player
  14. meta tags doesnt fetch data from permalinks
  15. Get arguments from URL
  16. Need print logo without any ID & class
  17. Add unique id to Preview URL
  18. How to properly set custom logo size?
  19. Convert multiple logos into the_custom_logo
  20. Need to convert image url to a Base_64 data url with wordpress function..
  21. Protect get_query_var from manual input in url
  22. Problem with images URL after filter applying
  23. How i can get the URL?
  24. include w_thumbnail_src in function?
  25. Create Custom URL structure for specific Post category using Post ID instead of post name
  26. Fetch URL parameter
  27. how can I change all wordpress media file url to custom cdn url?
  28. Custom route and extract data from slashes and parameter
  29. reWrite wp-content url to point on my cdn
  30. How to Override Page Template if URL matches query?
  31. Add #primary at the end of navlink permalinks on single posts
  32. Set URL Parameter Post Layout As Default
  33. Using Switch Statement to Change Image According to Last Digit of Topic ID
  34. Help! Need a different logo on my main page from my other pages
  35. Instead of using $post, how do i get the thumbnail image of the $post
  36. How to add a meta information to the URL?
  37. How do I change the URL returned by next_posts_link()?
  38. Function in functions.php by url
  39. Solution to render Shortcodes in Admin Editor
  40. How to run a function every 5 minutes?
  41. Modify Admin Bar Link
  42. How to override admin-bar style
  43. WP 4.4. responsive loads normal image after loading the responsive image
  44. How can I tell if I’m on a login page? [duplicate]
  45. Get Category and Excerpt From wp_get_recent_posts
  46. Two different menus for two different locations?
  47. Error after editing functions.php
  48. How do I properly register bootstrap JavaScript into WordPress functions.php?
  49. Manipulate Output of wp_list_something: select menu instead of li’s
  50. how to fix Warning: Use of undefined constant _ – assumed ‘_’ (this will throw an Error in a future version of PHP)
  51. restore_current_blog required after switch_to_blog, if I use that in a function?
  52. ‘is’ functions and ‘get_query_var’ not working
  53. How to get the post_name when in preview?
  54. “is_new_day()” alternative for years?
  55. How to hide a plugin metabox for non admins when a user adds a new post
  56. Getting Featured Image Caption to Only Show if Populated
  57. How do I create page navigation linking to each H2 within the page? [closed]
  58. How can I make a widget shortcode to control all the widgets?
  59. admin-ajax.php + load-scripts.php hanging for minutes
  60. Unique sequential reservation code
  61. Accessing two databases wordpress
  62. Add a jQuery Function
  63. append to existing parent theme function
  64. Get category URL for current post
  65. How can I get the post id from within functions.php
  66. How to set the WordPress logo programmatically with PHP
  67. I have problems with loading javascripts
  68. How do I change a parent theme’s function through the child theme?
  69. Dropline menus — seperators between children only?
  70. Echoing function into WordPress NextGen gallery
  71. does wp function the_content(); accept another tag inside
  72. Redirect to other page if login
  73. Are innerHTML elements visible to jQuery functions?
  74. Help with IF has focus then… statment
  75. How d0 i get the number of attachments in the post
  76. How to use wp_enqueue_script properly?
  77. This code is supposed to only allow user to be authenticated if accountVerified is equal to 1, but it still allows user to be authenticated otherwise
  78. Get webpack to work on child theme
  79. Hide ‘add to cart’ when certain value in dropdown is selected
  80. Enqueue script if not page template
  81. How do you insert code into the sidebar?
  82. Test CDN link from function.php or wp_enqueue_script/style?
  83. Auto Resize embedded videos player
  84. Can site visitors view functions.php file?
  85. Images with overlay
  86. Combine multiple menus using the filter wp_nav_menu_items
  87. Changing author links on homepage to buddypress profiles – without affecting ability to link to author archive throughout the site
  88. WordPress function with attribute pass to template
  89. Taxonomy On Index Page
  90. I see edit instead of read more
  91. How to exclude posts with empty and non-existent relational custom field with meta_query?
  92. How to replace words in my posts and saved new words
  93. Why might wptexturize have become re-enabled?
  94. Problem in shortcode outputting content
  95. How to use different jquery function of idangero swiper dependant on page template?
  96. Why does modifying my functions.php file always result in a server error
  97. wp_get_current_user->user login returns %20 for spaces
  98. Disable every rss feed except home feed
  99. If two tags in the middle i need comma
  100. Custom function wordpress php
Categories functions Tags functions, logo, urls
Exclude some posts from displaying in wp_query based on some condition
Second page of RSS feed

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress