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 change logo by category

Based on the comments I think I can walk you through this.

If you want to “inject” code like this into your theme, one of the better ways is with WordPress Action API.

Since what you’re trying to get on your site is Javascript, we’ll hook into the footer. Assuming your theme is built properly, adding this to your functions.php will add some code to the bottom of your site, on all pages:

add_action('wp_footer', function(){
    echo "<mark>👋 Hello</mark>";
});

If we then add in your conditionals, we can make that message only show on your categories page. See if the Hello message is on the page you want, and shouldn’t be on pages you don’t want.

add_action('wp_footer', function(){
    if (is_category(10) || cat_is_ancestor_of(10, get_query_var('cat')))
        echo "<mark>👋 Hello</mark>";
});

If that didn’t work, is_category() is just arguing against $wp_query. So we can review the $wp_query for the page you’re after, to ensure you’re conditionalizing the right things. Visit the page where the logo should change, and see what the cat value is:

add_action('wp_footer', function(){
    global $wp_query; 
    echo "<pre>".print_r($wp_query,true)."</pre>";
    //if (is_category(10) || cat_is_ancestor_of(10, get_query_var('cat')))
    //  echo "<mark>👋 Hello</mark>";
});

If it did work, or you resolved why it didn’t, we’ll we’re golden. You conditionals are fine. Now it’s just a matter of adding your script:

add_action('wp_footer', function(){
    if (is_category(10) || cat_is_ancestor_of(10, get_query_var('cat'))) {
        ?>
        <script>
            document.getElementsByClassName('logo')[0].src="https://wordpress.stackexchange.com/questions/290705/adventurelogo.png";
        </script>
        <?php
    }
});

If that doesn’t work, but the Hello message did, your issue is with your Javascript code. And well, that’s probably it too, looking closer at your JS code, you’re using the logo as a relative path – which won’t work if you’re using named permalinks. You need an image src with the full image URL. Assuming adventurelogo.png is in the root of your theme, it’d be more like:

add_action('wp_footer', function(){
    if (is_category(10) || cat_is_ancestor_of(10, get_query_var('cat'))) {
        ?>
        <script>
        var newLogo = '<?= get_template_directory_uri() ?>/adventurelogo.png';
        document.getElementsByClassName('logo')[0].src = newLogo
        </script>
        <?php
    }
});

Related Posts:

  1. get taxonomy thumbnail and use it as a variable in code
  2. go to home page when i select default in select-box
  3. How can i show specific Category List?
  4. Show subcategory name selected in specific category woocoommerce
  5. Custom Logo URL | Help me print the URL of the custom logo I inserted into my theme
  6. admin-ajax.php responding with 0
  7. Using wp_localize_script to store the template url into a variable to use in JS
  8. How can the plugin directory path be returned into ?
  9. Get posts with at least one category in common with current post?
  10. How to exclude specific category from the get_the_category(); array
  11. Add HTML Attributes To Anchor Tags In `wp_list_categories()` Function
  12. How can I add tinymce editor in WordPress with jQuery?
  13. How to speed up admin-ajax.php in wordpress
  14. JQuery not working on WordPress Admin page [closed]
  15. Customizer Show/Hide
  16. Page Reloads Before AJAX Request Finishes
  17. Woocommerce – remove product from category
  18. Get category name from custom loop and echo it once
  19. Display all categories including sub categories
  20. Colorbox ajax loading of outside HTML content works perfect on localhost but not on server
  21. How to make custom total price reactive in navigation
  22. Adding tawk.to code just before body tag on functions.php file
  23. How do I fetch all comments per post via WP REST API?
  24. Deregistering a script in WordPress seems impossible
  25. Slide in Panel WordPress Post
  26. Sending jsPDF documents to the server
  27. How to prevent those PHP variables from being cached on WordPress?
  28. Ajax return code 400
  29. How can I add an alert (like the old javascript alerts) to my WP page?
  30. Pass PHP variable to JavaScript without inline JS
  31. Custom category code not showing all posts
  32. Show post in slider
  33. How can I output a php value into a JS file within WordPress?
  34. Using shipped version of jquery
  35. Putting PHP variables into javascript [duplicate]
  36. Category Thumbnail Display – How to display ONLY the main Category
  37. Where do posts get the sidebar from?
  38. Bridging TinyMCE js and WordPress PHP?
  39. Trying to implement Ajax comments in WordPress, getting WP error
  40. How to test nonce with AJAX – Plugin development
  41. How do I display a user’s previous orders as a select box option on a product?
  42. Simple Plugin with custom javascript wont work – no console error
  43. How does this WordPress Plugin (Thrive Comments) apply their custom comment sort? [closed]
  44. How can I use a modal window to display the current post in loops featured image?
  45. js file in root loading without
  46. hover image appears below placeholder instead of overlayed
  47. combine Code 1 with Code 2
  48. get current product name in functions.php
  49. class click counter save number
  50. Trigger popup in a php if/else statement
  51. get post based on category chosen in drop down – The ajax method
  52. How to use transient in this code for related post?
  53. Slider loading issue
  54. Changing custom logo link
  55. AJAX request status 200 but no actual “response”
  56. Button not refreshing page
  57. Ajax not working es expected (Returns 0)
  58. Creating a related post section based on similar categories
  59. Use menu link or onClick to set a variable
  60. Swapping wp_dropdown_categories function with wp_category_checklist
  61. How to select the contents in the text view textrea in wp_editor?
  62. Creating a Multi-Level Associative Object Using AJAX
  63. WP functions in .js
  64. Adding custom directory and PHP files in wordpress
  65. Theme Options Page – User Updates Logo
  66. Proper syntax or method for keeping url in modified isotope / category links
  67. Ajax – Call to undefined function get_option()
  68. Filter Select results based on selection
  69. What is an equivalent of single_cat_title for getting the slug of the category?
  70. Populate dropdown with Child Pages based on Parent Page chosen
  71. remove wp floating submenu in wp dashboard
  72. Issue adding sub category programmatically
  73. Displaying admin notices inside the block editor from rest_after_insert_{$this->post_type} hook
  74. search and replace preword from author
  75. How to prevent XSS alter custom global javascript object & methods in WordPress
  76. How to exclude category ID from Looper in WordPress
  77. How to complete two other input fields, completed the first
  78. Add a specific part of current category page url to shortcode
  79. Status 400 for AJAX POST Request with admin-ajax.php
  80. how do I get a specific post from a post with a subcategory in WP
  81. How to inject variables into public-facing JS using wp_enqueue_script
  82. How to pass aa JS variable to PHP?
  83. Customize Theme comment template to Insert VoteUp and VoteDown buttons
  84. WP grandchild categories in nested ul li
  85. Ajax random number always the same
  86. Image upload via FormData API and AJAX is not working ($_FILES always empty)
  87. Grab posts by multiple categories
  88. Pass Category Name, Description and Photo into variables to pass to jQuery
  89. I have a problem in the order of enqueues while enqueuing stylesheets and scripts for a specific page in my function.php
  90. How to show single category archive
  91. JS file work only in index page
  92. Move category description below post list in blog
  93. Need Help Fixing My Iframes [closed]
  94. How to pick the default selected value in wordpress dropdown?
  95. wp_enqueue_scripts leads to error
  96. Javascript file is not working on single.php wordpress [closed]
  97. Applying A Category to Existing Posts Where Page Title Matches Regex
  98. Get page that displays all children of taxonomy parent
  99. How to change redirection route to a php page for making it only accessible by logged-in members?
  100. Integrating PHP into Javascript to display map markers with Google API – problem with wp_localize
Categories PHP Tags categories, javascript, logo, php
Custom taxonomy link automatically removing query string and re-directing
WordPress meta_query >= &

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