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

Started by Douglas, December 30, 2019, 10:14:33 AM

Previous topic - Next topic

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:
<title>', $context['page_title'], '</title>';

For SMF 1.x and 2.0.x,  add BEFORE:
<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>


(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:

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


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)
Doug Hazard
* Full Stack (Web) Developer for The Catholic Diocese of Richmond
(20+ Diocesan sites, 130+ Church sites & 24 School sites)
* Sports Photographer and Media Personality
* CFB Historian
* Tech Admin for one 1M+ post, one 2M+ post and one 10M+ post sites (last two are powered by multiple servers)
* WordPress Developer (Junkie / Guru / Maven / whatever)

Advertisement: