最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wordpress - How can I show different logos for test.domain.com and test2.domain.com on the same website? - Stack Overflow

programmeradmin3浏览0评论

Two domains should point to the same website (test.domain and test2.domain). When someone visits test.domain, it should display the main logo. When someone visits test2.domain, it should display a different logo.

I am using WordPress and the free version of Elementor.

How can I achieve this?

Two domains should point to the same website (test.domain and test2.domain). When someone visits test.domain, it should display the main logo. When someone visits test2.domain, it should display a different logo.

I am using WordPress and the free version of Elementor.

How can I achieve this?

Share Improve this question asked Mar 14 at 9:42 Anto NavisAnto Navis 4210 bronze badges 1
  • It looks like your question could use a bit more detail. What have you tried so far? Including error messages, and relevant code snippets will help others understand your issue better and provide more useful answers. You might also want to check out How to Ask for tips on improving your question! – OverdueOrange Commented Mar 14 at 10:03
Add a comment  | 

1 Answer 1

Reset to default 0

Your question is not clear enough. There can be two cases:

Case 1: WordPress Multisite

You can enable the WordPress Multisite feature to use a different logo (or even completely different content) for different subdomains within a single WordPress installation.

Case 2: Different Logos for Subdomains in a Single WordPress Site

If you want to use the same WordPress installation (not Multisite) but display a different logo based on the subdomain, you can achieve this using CSS and JavaScript.

Step 1: Add a Custom CSS Class to the Logo

  1. Edit the Header Template in Elementor (where your logo is located).
  2. Click on the logo widget.
  3. Go to the Advanced tab.
  4. Find the CSS Classes field and add a custom class (e.g., custom-logo).
  5. Click Update to save changes.

Step 2: Add Custom JavaScript

  1. Go to WordPress Dashboard → Elementor → Custom Code.
  2. Click "Add New Custom Code".
  3. Enter a name (e.g., "Custom Logo Script").
  4. Paste the following JavaScript inside the editor.
  5. Set Location to Footer (better for performance).
  6. Click Publish and set conditions (e.g., "Entire Site").
  7. Click Save & Close.

Custom JavaScript Code

document.addEventListener("DOMContentLoaded", function () {
    let logo = document.querySelector(".custom-logo img"); // Target logo
    if (!logo) return; // Exit if logo not found

    let host = window.location.hostname; // Get subdomain
    if (host === "test2.domain") {
        logo.src = "https://your-site/wp-content/uploads/alternate-logo.png"; // Change logo for test2
    } else {
        logo.src = "https://your-site/wp-content/uploads/main-logo.png"; // Default logo
    }
});

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论