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. Is there a way to batch-find unlinked text URLs in the body text of all my posts and link them?
  40. Missing feature image link function
  41. Remove “Category:”, “Tag:”, “Author:” from the_archive_title
  42. get_template_directory_uri pointing to parent theme not child theme
  43. How to customize the_archive_title()?
  44. remove empty paragraphs from the_content?
  45. What is the “with_front” rewrite key?
  46. Why use if function_exists?
  47. How to override parent functions in child themes?
  48. wp_enqueue_script was called incorrectly
  49. Add multiple custom fields to the general settings page
  50. Ajax call always returns 0
  51. 400 bad request on admin-ajax.php only using wp_enqueue_scripts action hook
  52. How long does a deprecated function live in core?
  53. Solution to render Shortcodes in Admin Editor
  54. How to add a data attribute to a WordPress menu item
  55. What’s the difference between esc_html, esc_attr, esc_html_e, and so on?
  56. remove_action on after_setup_theme not working from child theme
  57. plugins_url vs plugin_dir_url
  58. Remove type attribute from script and style tags added by WordPress
  59. How to run a function every 5 minutes?
  60. Best way of passing PHP variable between partials?
  61. Upload Multiple Files With media_handle_upload
  62. How to display custom field in woocommerce orders in admin panel?
  63. Adding fields to the “Add New User” screen in the dashboard
  64. Issues with title-tag and document_title_parts
  65. How do I get the current edit page ID in the admin?
  66. How to check if a user exists by a given id
  67. Why isn’t is_page working when I put it in the functions.php file?
  68. Add tags to the section via functions.php
  69. Add image size if page template
  70. How to create a custom order status in woocommerce!
  71. Remove Actions/Filters added via Anonymous Functions
  72. Adding a second email address to a completed order in WooCommerce [closed]
  73. How to load parent_theme functions.php before child_theme?
  74. How to load scripts/styles specific for a page
  75. Programatically add options to “add new” custom field dropdown
  76. Is there any global functions.php file which works for any theme?
  77. Excluding iPad from wp_is_mobile
  78. When should you, and when should you not, use wp_list_pluck()?
  79. Get the ID of the page a menu item links to?
  80. Add container to nav_menu sub menu
  81. Difference between the_permalink() and get_permalink() function
  82. What’s the difference between WordPress random_int() and PHP built-in function random_int()?
  83. Child theme – Overriding ‘require_once’ in functions.php
  84. Link to user’s profile settings page?
  85. WordPress Enqueue for homepage only, functions.php, wp-framework
  86. get php variable from functions php and echo it in theme template files [closed]
  87. Get menu object from theme_location
  88. Is it ok to use a function to output the text domain name in a wordpress theme
  89. Displaying the number of updates available in the Admin area
  90. Trying to use add_action and do_action with parameters
  91. Use AJAX in shortcode
  92. Set JPEG compression for specific custom image sizes
  93. Can the new 4.8v text widget visual editor be removed?
  94. Include files in child theme functions file
  95. Memorizing syntax
  96. Define page template in wp_insert_post
  97. Which WP functions do you need to use esc_html() or esc_url() on?
  98. Check if post is being published for the first time, or is an already published post being updated
  99. Display random categories on the front page (Finding and Editing Theme Functions)
  100. How to redirect to post if search results only returns one post
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
  • Post Navigation Elementor
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • WPFacet multiple loop displaying duplicate content
  • Get the name of the template/*html file used
  • Fix: WordPress.DB.PreparedSQL.NotPrepared Plugin Check (PCP)
  • Removing unnecessary CSS and JS code from wp_head()
  • hexagonal image gallery. Am I on the right track? [closed]
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
© 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