Customizing SMF > Tips and Tricks

[HOW TO] When SMF is running in an iframe, change the parent's <title> text

(1/1)

Douglas:
Question: How do I change the parent's page title text (inside <title></title) when running SMF in an iframe?
Original Topic: https://www.simplemachines.org/community/index.php?topic=564468.0

(Note: This wasn't an issue that was posted, however, it was something I needed to have solved, in order for our site visitors to be kept happy).

(Note 2: You should really do this off a CHILD theme, so that your changes are not overwritten any time there is an update to SMF's core themes).

Open [YOUR SMF THEME DIRECTORY]/index.template.php
Find:

--- Code: --- <title>', $context['page_title'], '</title>';
--- End code ---

For SMF 1.x and 2.0.x,  add BEFORE:

--- Code: --- <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script>parent.document.getElementsByTagName("TITLE")[0].innerHTML= "', $context['page_title'], '";</script>

--- End code ---

(Note 3: For SMF 1.x and 2.0.x, get the current (latest) jQuery CDN code from https://code.jquery.com/.)

For SMF 2.1.x,  add BEFORE:

--- Code: --- <script>parent.document.getElementsByTagName("TITLE")[0].innerHTML= "', $context['page_title'], '";</script>

--- End code ---

This should work on ALL page types that have an iframed SMF... even WordPress (testing of this was done on a WordPress page with SMF 1.x running inside an iFrame)

Navigation

[0] Message Index

Go to full version