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 to set the WordPress logo programmatically with PHP

The logo is a theme mod, so you can set it with set_theme_mod( 'custom_logo', $value );, but the value needs to be an attachment ID, so you’ll need to upload it first.

If you don’t want to upload anything, you can use the get_custom_logo() filter to provide your own HTML for the logo. If you want to mimic the way WordPress does it, just make sure to include the link custom-logo classes:

function wpse_304465_custom_logo( $html ) {
    if ( $html == '' ) {
        $html = sprintf( 
            '<a href="https://wordpress.stackexchange.com/questions/304465/%1$s" class="custom-logo-link" rel="home" itemprop="url">%2$s</a>',
            esc_url( home_url( "https://wordpress.stackexchange.com/" ) ),
            '<img src="http://www.example.com/myimage.png" class="custom-logo" itemprop="logo">'
        );
    }

    return $html;
}
add_filter( 'get_custom_logo', 'wpse_304465_custom_logo' );

Related Posts:

  1. Custom Logo URL | Help me print the URL of the custom logo I inserted into my theme
  2. Changing custom logo link
  3. Logo custom width not implementing
  4. Creating posts with php-script + csv
  5. How to set and use global variables? Or why not to use them at all
  6. How to deprecate a function used in a plugin?
  7. How to manually fix the WordPress gallery code using PHP in functions.php?
  8. How to make a image-size selected by default in Media upload – WP v3.5
  9. What is This esc_html_e() i wordpress php?
  10. Error Warning: Declaration of description_walker::start_el after PHP upgrade [duplicate]
  11. How to Add Image to WordPress RSS-Feed with no Plug-in?
  12. Function to return true if current page has child pages
  13. How do I change/modify the_post_thumbnail(); html output?
  14. Mega Menu Walker
  15. start_lvl Ignored in Custom walker_nav_menu
  16. Enforcing password complexity
  17. PHP code in page template vs functions
  18. Apply class to every paragraph that holds image?
  19. Remove “Insert from URL” link in Media upload – WP 3.5
  20. static variable loop not working in WordPress
  21. Cleaning up WordPress to improve performance?
  22. Displaying Logged-In User Name in WordPress Menu
  23. Hide main div if wp_nav_menu is empty
  24. Proper use of Output Buffer
  25. List of all theme customizer control types?
  26. Autoloading in Child Theme
  27. Does My Child-Theme Functions.php Need if{die} Security In It? [duplicate]
  28. Modify previous and next text from pagination links
  29. Allowed memory size of 268435456 bytes exhausted (tried to allocate 7146491840906359738 bytes)
  30. How to add a class to the attachment images
  31. Need help setting default setting value for radio button in theme customizer
  32. How to call a function only once (global variable scope)
  33. Multiple is_page() in page.php
  34. Should I write a PHP function in home.php?
  35. Removing Default Gutenberg Blocks, But Keeping Reusable Block Functionality?
  36. Edit tag cloud widget number
  37. adding a filter to a shortcode?
  38. username_exists() function can’t be access without logging in
  39. Customize default settings on new sites on multisite
  40. Set media upload attachment link to none and hide it in WP v3.5
  41. How can I modify the permalink via a filter?
  42. How to draw media details for Isotope gallery using Photoswipe
  43. How to call a PHP function from Javascript in WordPress
  44. How to automatically apply woocommerce product title to all product images alt tags?
  45. How to store the_title() into a variable to reutrn the value, not just echo it
  46. exclude multiple terms using get_terms() function
  47. Create a global variable for use in all templates
  48. Is it possible to disable a function of a parent theme?
  49. Add Useragent to the body class?
  50. How do I make my function add variables/values to the $post object?
  51. Hide old attachments from wp media library
  52. How to override an unpluggable parent theme function?
  53. PHP – redirect https to http and www to non-www
  54. function_exists call in function.php
  55. How to register images uploaded via FTP in media library?
  56. Fatal error: Call to undefined function plugin_dir_path()
  57. Switching wp_get_sites to get_sites
  58. Check if a menu is empty?
  59. wp_set_object_terms and arrays
  60. WordPress Infinite Scroll without using any plugin
  61. Build a content and excerpt grid loop with paging and options for # of posts
  62. Shortcode putting html such as
  63. How to preserve PHP modifications while upgrading WordPress?
  64. Is it possible to get a theme customizer setting from wp.customize using jquery?
  65. Debugging an error: wp_enqueue_style was called incorrectly
  66. How to log out everywhere else, destroy all sessions “all other devices”?
  67. how to get permalink structure with php
  68. Inserting Gravity Form checkbox values into Advanced Custom Fields [closed]
  69. Change the footer text on the login page
  70. How to remove a metabox from menu editor page?
  71. How do I remove a require_once admin panel from the parent theme from the child theme functions.php?
  72. Should the value of core functions be escaped before outputting?
  73. How to get the registered sidebar’s name by its id?
  74. Remove wp-mediaelement.css from wp_head
  75. How do I get the author’s page url from their ID?
  76. Why is my custom meta box input not saving
  77. add_filter to post-gallery and remove all ‘s?
  78. Dynamic URL to reference custom PHP files
  79. How to correct schedule my event weekly with wp_schedule_event()
  80. Set the transport of the Customizer ‘header_image’ core setting to ‘postMessage’
  81. Calculate percentage of post by category
  82. Can i check if user is doing any ajax request?
  83. the_post_thumbnail() based on the Post ID
  84. How to get the original price of the product in woocommerce?
  85. Displaying post per day
  86. Dynamically change feature image in customiser
  87. How to overwrite youtube embed?
  88. One button to change all settings in theme customizer?
  89. Rewriting search and pagination base
  90. Woocommerce auto cancel On-Hold after X days
  91. Check if page parent has certain template
  92. Counting number of posts in a category and its sub categories and displaying result using shortcode
  93. class=”parent” for wp_list_pages?
  94. Calling a method from functions.php on a click of a button
  95. Enqueue Javascript Correctly for 3.5
  96. Shortcode created to check language not works
  97. How to redirect users to custom lostpassword page?
  98. Change comments form title on a page by page basis
  99. Allow authors to post only in categories they create in WordPress
  100. Creating wordpress user registration form
Categories PHP Tags functions, import, logo, php
add_action template_redirect not working for home page
Why is WP_Query not displaying expected data?

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