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

Custom Logo URL | Help me print the URL of the custom logo I inserted into my theme

Use wp_get_attachment_image_src to get the image properties and URL:

$logo = get_theme_mod( 'custom_logo' );
$image = wp_get_attachment_image_src( $logo , 'full' );
$image_url = $image[0];
$image_width = $image[1];
$image_height = $image[2];

Edit: Adding more information based on your comment.

The URL it points to is simply made with home_url:

esc_url( home_url( "https://wordpress.stackexchange.com/" ) );

Another thing often forgotten when using this method is honoring the content of the alt if it’s set in the media:

$alt = get_post_meta( $logo, '_wp_attachment_image_alt', true );
if ( empty( $alt ) ) {
    // Use site title if no alt is provided.
    $alt = get_bloginfo( 'name', 'display' );
}

I’d encourage looking at the source of get_custom_logo as it would use most of this.

It’s also worth mentioning if you’re developing this theme for release on WordPress.org/themes – it’s a requirement to use the_custom_logo or get_custom_logo over rolling out your own solution.

For this reason there is a filter for the HTML output in get_custom_logo, which might be best to use and replace the bits you need. The function get_custom_logo (used by the_custom_logo) also handle a bit more like multisite and ensuring the placeholder is there for the customizer preview. The usage would be something like this:

add_action( 'get_custom_logo', function( $html ) {
    $new_url="href="" . get_theme_mod( 'custom_logo_url', esc_url( home_url( "https://wordpress.stackexchange.com/" ) ) ) .'"';
    $new_link_class="class="box-link"";
    $html = str_replace( 'href="' . esc_url( home_url( "https://wordpress.stackexchange.com/" ) ) . '"', $new_url, $html );
    $html = str_replace( 'class="custom-logo-link"', $new_link_class, $html );
    return $html;
} );

That would read a value of the theme_mod custom_logo_url which could come from a customizer control, and changes the class from .custom-logo-link to .box-link in your example.

Related Posts:

  1. Function to return true if current page has child pages
  2. Proper use of Output Buffer
  3. List of all theme customizer control types?
  4. Need help setting default setting value for radio button in theme customizer
  5. function_exists call in function.php
  6. Is it possible to get a theme customizer setting from wp.customize using jquery?
  7. Debugging an error: wp_enqueue_style was called incorrectly
  8. How to get the registered sidebar’s name by its id?
  9. Set the transport of the Customizer ‘header_image’ core setting to ‘postMessage’
  10. Dynamically change feature image in customiser
  11. One button to change all settings in theme customizer?
  12. Hide a menu-item and its submenus and display a ‘Log in’ link if the user is logged out
  13. The best way to customize “nav-menu-template.php” to add if the ‘link_before’ is “checkbox”
  14. Design view breaking on Pages
  15. Understanding WordPress child theme custom JS loading
  16. How can I loop into two different DIVS without repeating the DIVs
  17. Removing unnecessary wordpress files
  18. Remove css styles from specific page
  19. Is the regular ajax request method safe or I should use admin-ajax.php?
  20. How do I list the_tags() into HTML data-attribute
  21. Can I change a variable in a content part while calling it?
  22. How to make thumbnail image fit into a div where image dimentions are completely different?
  23. What is the fastest way to load PHP functions that are only used in one theme template?
  24. My Own layout in WooCommerce pages [closed]
  25. Differences when using the the_time and the_date functions
  26. Can’t load WP function into external function
  27. Set WordPress Default Template
  28. Trigger popup in a php if/else statement
  29. Changing custom logo link
  30. Create another “Display Site Title and Tagline” checkbox, “Header Text Color” setting and control
  31. Theme Options Page – User Updates Logo
  32. Converting HTML Template to WordPress Theme
  33. How to remove the cufon script from Dzonia Lite theme [closed]
  34. How do I add custom bulk actions to multiple custom post types?
  35. what is the best practice to add new field to an api route
  36. Error in custom php function doesn’t exist
  37. Populate editor with some content of a page with a page template
  38. Catchable fatal error: Object of class stdClass could not be converted to string after WP 4.7
  39. Compare the old get_theme_mod($name) to the new get_theme_mod($name) return value
  40. Skt full width basic slideshow problem
  41. How to disable controls in theme customizer?
  42. How do I link a button I created in theme customizer to a function?
  43. Trying to retrieve post meta
  44. Is there a way to conditionally check whether a WordPress post title is empty?
  45. Is the “_s” on this `sprintf(__(‘Page %s’, ‘_s’), max($paged, $page))` just refer to a text domain?
  46. WordPress admin-ajax.php
  47. Use .php file as page instead of wordpress page & template file?
  48. Use WordPress function in php file
  49. How to obtain the current website URL in my theme?
  50. What exactly do this function declared into functions.php file of a WP theme?
  51. How to set the WordPress logo programmatically with PHP
  52. How to call multiple functions from multiple files into a WordPress page template [closed]
  53. get_template_directory adding FTP root folders in urls
  54. Theme not calling Jquery properly
  55. What is the best way to define constant options for a theme?
  56. How to make function appear in sentence?
  57. Removing “Powered by” footer using child theme PHP [closed]
  58. How to add aria role and schema markup to custom walker container
  59. get_page_templates only return templates with “home” in the filename
  60. Is there a hack for using is_page() within the function.php file?
  61. Extract and display user infromation on an automatically created page
  62. Show different website layout if no sidebar added
  63. How can I assign separate stylesheets to different pages?
  64. Need advice on theme customizer and child themes
  65. How to make sure relative URL works when site is not on root domain?
  66. Getting text from custom field from customizer
  67. Dynamically switch file in get_template_directory_uri() | Function [closed]
  68. Need help for some PHP code
  69. Uncaught TypeError: extract(): Argument #1 ($array) must be of type array, null given
  70. How to change basename url for wp-admin?
  71. how to replace h1 entry title with h2 in category pages only
  72. Problem with displaying CSS Stylesheets – Am I adding them correctly in my wordpress child theme?
  73. require get_template_directory() . ‘path/to-my/file.php’ BREAKS customize > themes functionality
  74. How can I prevent a shortcode div from extending beyond its boundaries?
  75. Logo custom width not implementing
  76. Menu to the right of screen on desktop using Bootstrap 4
  77. Theme editing “post thumbnail” help
  78. Where can I find the declaration of `$_wp_theme_features`?
  79. Calling PHP function doesn’t work in index.php
  80. Extend the WP_Customize_Image_Control class to change its non-frame $button_labels
  81. A Customizer checkbox control that sets the setting to “” or to “blank” and show() or hide() a color control
  82. My customizer’s setting doesn’t set to the default and needed to click the control’s “Default” button before it’ll be set
  83. Save the outputted image into the Media Library, with a different filename and extension
  84. WordPress get_post_meta issue
  85. WordPress causing all code to be displayed on line 1. Receiving multiple errors after cleaning cookies and cache
  86. How to add button to top of theme customizer?
  87. Adding code to the function file
  88. Adding php within a return statement [closed]
  89. I need a button to appear when not loged in and another when logged in, I need help fixing code PLEASE!
  90. Load slideshow.css file only if Slideshow is checked / on
  91. How can I fix my pagination?
  92. require used as a function to load theme dependencies?
  93. Get first URL from post content
  94. Setting custom canonical urls
  95. Using a variable in is_page(array())
  96. Handling Body class based on Template
  97. Anyway to output the registration form like the login form with wp_login_form()?
  98. How do I get current page ID in WordPress customizer file?
  99. Setting a cookie upon specific URL visit
  100. Get_avatar filter?
Categories PHP Tags functions, logo, php, theme-development
How to execute existing WP Cron programmatically
disable (read only) a field if within a custom post type name

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