Step-by-Step Guide to Adding rel="nofollow noopener noreferrer" to Links in Osclass Using JavaScript
Step 1: Open the Template File
In Osclass, template files are located in the following folder:
swift
КопироватьРедактировать
/oc-content/themes/YOUR_THEME/
The description of the ad is usually displayed in the item.php file.
Step 2: Find the Ad Description Block
In the item.php file, find the line responsible for displaying the ad description. It might look like this:
php
КопироватьРедактировать
<?php echo osc_item_description(); ?>
or be inside a <div class="description">, <p class="desc">, etc.
Step 3: Add JavaScript Code Before the Closing </body> Tag
Insert the following code before </body>:
html
КопироватьРедактировать
<script>
document.addEventListener("DOMContentLoaded", function() {
document.querySelectorAll(".description a").forEach(link => {
link.setAttribute("rel", "nofollow noopener noreferrer");
});
});
</script>
Code Explanation:
- document.addEventListener("DOMContentLoaded", function() {...}); — Ensures the code runs after the page loads.
- document.querySelectorAll(".description a") — Selects all <a> links inside the .description block.
- link.setAttribute("rel", "nofollow noopener noreferrer"); — Adds the required attributes to each link.
Step 4: Save and Test the Changes
- Save the item.php file.
- Open an ad page in your browser.
- Right-click on a link in the description and select Inspect Element.
- Check that the links now have rel="nofollow noopener noreferrer".
Troubleshooting
If the changes don’t take effect:
- Clear your browser cache (Ctrl + Shift + R).
- If you're using cache plugins, clear the Osclass cache.
After this, all links in ad descriptions will have the required attributes.
Post automatically merged:
If there are any errors, send them, and I will improve them, then make a plugin and post it.
Last edited: