News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

[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)
* HBCUAC.org Web Developer, the NAIA's only HBCU Athletic Conference
* Former Sports Photographer and Media Personality and Former CFB Historian
* Tech Admin for one 2.9M+ post and one 11.6M+ post sites. Used to own a 1M+ post site.
* WordPress Developer (Junkie / Guru / Maven / whatever)

Advertisement: