During website development and maintenance, ads embedded in templates can negatively affect user experience. For sites built with Dedecms, default templates or certain extensions may include intrusive ad blocks.
The most straightforward method is to manually delete ad-related code from the template files. In the Dedecms admin panel, go to the “Template Management” section and locate files such as index.htm or list.htm. Search for keywords like "ad" or "advertisement" to identify the code blocks.
These are typically placed inside
<!-- This is ad code --> <div class="ad-banner"> <a href="http://www.example.com/">@@##@@</a> </div> <!-- End of ad code -->
If the ad code cannot be removed directly, CSS can be used to hide the elements. Locate the class or ID associated with the ad in your CSS file and add the following:
.ad-banner { display: none !important; }
This approach keeps the ad code in the source, but it will not be visible to users in the browser.
For sites with ads spread across multiple template files, Dedecms offers a “Batch Replace” feature within the Template Management section. You can use regular expressions to identify and remove all ad elements at once.
Example: Target div blocks with specific class names and replace them with an empty string.
Customize the regular expression according to your actual ad structure. For instance:
<div class="ad-banner">[\s\S]*?<\/div>
Replace with: (leave this field empty to remove matched content)
By using the methods above—editing templates directly, hiding elements with CSS, or applying regular expressions—you can effectively eliminate ads from your Dedecms website. This improves page clarity, enhances SEO performance, and ensures a better user experience.
Be sure to back up your template files before making changes, to avoid any unintended issues with your site layout.