axew3.com

phpbb-wordpress-template-integration-iframe-v6

—

by

V6 release (still for the cool people!)

WordPress phpBB iframe template integration

JS code – updated on 24 Jul 2024

Help steps – updated on 28 Nov 2026

Note: available since 3.2.8.5

WordPress shortcode

Example:

[w3allphpbbiframe wp_page_name="forums" wp_page_iframe_top_gap="300"]
  • The wp_page_name parameter refers to the slug of the page or post where the shortcode will be added (see the hint below regarding what happens if this parameter is omitted*).
  • The wp_page_iframe_top_gap parameter specifies (in pixels) the default scroll position on the parent WordPress page. If omitted, it defaults to 0.
  • The url_push parameter defaults to “yes” if omitted, meaning that when links are clicked inside the phpBB iframe, the updated URL will be pushed to the browser’s address bar. If you want to disable this behavior, add url_push="no" to the shortcode.
  • The fancy_url parameter must match the value you set in the code added to overall_footer.html and overall_header.html (see the required phpBB steps below) if you changed it from the default “w3”.
  • The phpbb_default_url parameter (which can be omitted) specifies a custom phpBB URL that the iframe will open by default. Using it, the shortcode will look like the example below—allowing to embed phpBB inside a WordPress post or page and open directly to a specific forum topic, post.
  • The scroll_default parameter is set to “yes” by default if omitted. To disable automatic page scrolling, set it to “no” like this: scroll_default="no".
[w3allphpbbiframe phpbb_default_url="https://www.axew3.com/w3/forums/viewforum.php?f=2" wp_page_name="forums" wp_page_iframe_top_gap="300" fancy_url="coding"]

See a working example further below.

If you need to customize the CSS, HTML output, or something else, here are the relevant files to check:

/wp-content/plugins/wp-w3all-phpbb-integration/common/wp_phpbb_iframe_shortcode_v6.php

and

/wp-content/plugins/wp-w3all-phpbb-integration/views/wp_w3all_phpbb_iframe_short_v6.php

Note that you can customize these two files. By enabling the “Use custom files to display Last Topics Widgets, Login Widget and Shortcodes” option in the plugin admin settings-and copying the modified files into the

/wp-content/plugins/wp-w3all-custom

folder-your changes will be preserved whenever the plugin is updated.

*Note on the wp_page_name parameter: If you are using Plain permalinks, the value should match the query string-for example, p=45 for a post, or page_id=12 for a page.

Required phpBB Template Changes

overall_footer.html code

Open with a text editor your phpBB template file overall_footer.html

and just before the closing </body> tag, add this code:

<!-- IF not S_IS_BOT -->
<script type="text/javascript">
// START MANDATORY CHANGES

var w3allAllowDomain = 'https://w3host.com'; // MANDATORY! Set/Change this value to fit the absolute domain (DO NOT ADD/INCLUDE final slash here)
var wordpress_url_page_forum = 'https://w3host.com/forum'; // MANDATORY! (DO NOT ADD/INCLUDE final slash here) Url that point to the wordpress forum page
var w3all_custom_wp_w3fancyurl = 'w3'; // MANDATORY! If you changed the default 'w3' query string to use a fancy URL, update this value to match the fancy URL setting in the shortcode.

// END MANDATORY CHANGES

var w3allappend = false;
var w3all_BoardUrl = "{BOARD_URL}";
w3all_BoardUrl = w3all_BoardUrl.slice(-1) != '/' ? w3all_BoardUrl + '/' : w3all_BoardUrl;

function w3allNormalize_phpBBUrl(href){
// try to 'normalize' passed relative links: needed all after last slash /
// exception are kind of passed urls like: /phpbb323/app.php/help/faq
// and if SEO mods that may assign some different kind of links values
// by the way, SEO absolute urls http(s) should be (all?) already considered here ...
var phpbbRUrl = href.split(/^.+?(\w+.+)$/);
if( href.indexOf('app.php') > -1 ){ // since the previous do not 'normalize' this type of passed value (and may miss something else)
   phpbburl = href.split(/^.+?(app\.php.+)$/);
   w3allappend = phpbburl[1];
 } else if ( /^https?/ig.exec(href) !== null ){ // absolute http(s) passed: try to 'normalize' a possible seo mod
   phpbburl = href.split(w3all_BoardUrl);
   w3allappend = phpbburl[1];
 } else if ( phpbbRUrl[1] && phpbbRUrl[1].length > 1 ){ // 'normalize' any other
   w3allappend = phpbbRUrl[1];
 } else if ( phpbbRUrl[0].length > 1 ){
   w3allappend = phpbbRUrl[0];
   }
// ... if still not normalized
if(/^\W/ig.exec(w3allappend) !== null){
  w3allappend = w3allappend.split(/^.+?(\w+.+)$/);
  if(w3allappend[1]){
    w3allappend = w3allappend[1];
  }
  if ( w3allappend[1] && w3allappend[1].charAt(0) == '/' ){
    w3allappend = w3allappend[1].substr(1);
  }
}
return w3allappend;
}

$(document).on("click", "a", function(e) {
  var href = $(this).attr("href");
  var w3all_onview_attach = (href.indexOf('file.php') > -1);

if( this.getAttribute('target') !== null ){
  e.preventDefault();
  window.open(href,'_blank');
 return;
}

if ( href.charAt(0) == '#' || href.indexOf('\./download\/file\.php') > -1 ){ return; }

// external link?
if ((this.href.indexOf(w3all_BoardUrl) > -1) != true){
 if(/^(f|ht)tps?:\/\//i.test(href))
 {
  e.preventDefault();
  parent.location.replace(href);
 return;
 }
}
// admin ACP?
if ( /\/adm\//ig.exec(href) !== null )
{
  e.preventDefault();
  parent.location.replace(href);
  return;
}

if ( href.indexOf('view=print') > -1 !== false || /\/adm\//ig.exec(href) !== null )
{
 e.preventDefault();
 window.open(href,'_blank');
 return;
}

if ( href.indexOf('quickmod') > -1 ) {
   w3allNOappend = true;
    return;
}

if( /posting\.php\?mode=[reply|post|bump]/ig.exec(href) !== null || /mcp\.php\?/ig.exec(href) !== null ){
  w3allNOappend = true;
}

if(w3all_onview_attach !== false){
 e.preventDefault();
 window.open(href,'_blank');
 return;
}

w3allappend = w3allNormalize_phpBBUrl(href);

if ('parentIFrame' in window){
  if( typeof w3allNOappend == 'undefined' || w3allNOappend == false ){
    window.parentIFrame.sendMessage(w3allappend);
  }
 }
});

// w3all UPDATES for phpBB events

if(window.self !== window.top){

// Lightbox scroll fix, #phpbb_confirm scroll fix, #phpbb_alert scroll fix, #bbcode_wizard + abbc3_button fix
$(".dropdown-contents-cp,.abbc3_button,.postimage,.dropdown-contents li a,#add_files").on("click", function(e) {
  var g = $($(this.getBoundingClientRect().top));
  var t = parseInt(g[Object.keys(g)[0]]);
  $("#bbcode_wizard,#phpbb_alert,#phpbb_confirm").animate({top: t+'px'}, 100);

 const w3LBfixImgs = setInterval(exec_w3LBfixImgs, 500); //1000
 function exec_w3LBfixImgs() {
   var imh  = parseInt($('.lb-image').css("height"));
   var lbOh = parseInt($('#lightboxOverlay').css("height"));
   var totH = imh+t;
    if(totH < lbOh){
      $("#lightbox").animate({top: t+'px'}, 400);
    } else {
      t = parseInt((lbOh-imh)-100);
      $("#lightbox").animate({top: t+'px'}, 400);
    }
   clearInterval(w3LBfixImgs);
 }
});

var pmn = "{PRIVATE_MESSAGE_COUNT}";
var w3all_phpbb_u_logged = "{S_USER_LOGGED_IN}";

var hash = window.location.hash.substr(1);

if( hash == 'unread' ){
 var postN = 1;
 $( "h3 > a" ).each(function (e) {
  ns = this.href.split('#p');
  if( typeof ns != 'undefined' && /viewtopic.php\?p=/ig.exec(this.href) != null ){
   if(ns[1] > postN){
     w3lh = ns[1];
    }
  }
 })

 if( typeof w3lh != 'undefined' ){
  hash = "p" + w3lh;
 }
}

$( document ).ready(function() {
 // fix vertical iframe centered in certain cases
   var bd = document.getElementsByTagName("body");
   var t = document.getElementById(bd[0].getAttribute("id"));

   if( typeof t != 'undefined' || t != false )
   {
         t.setAttribute("style", "position:fixed;top:0;left:0;width:100%;padding:0");
      //t.setAttribute("style", "position:fixed;top:0;left:0;width:100%;");
   }
});

if( typeof w3allNOappend == 'undefined' || w3allNOappend == false )
{
 $( window ).on( "load", function()
 {
  location.hash = "#" + hash;
  if( ! $(window.location.hash).length || location.hash.length < 2 ){
    var w3all_lochash = 0;
  } else {
    var w3all_lochash = $(window.location.hash).offset().top;
  }

  var w3appendevents = '#w3all_phpbbpmcount=' + pmn + '#w3all_phpbb_u_logged=' + w3all_phpbb_u_logged + '#w3all_lochash=' + w3all_lochash;

  window.parent.postMessage(w3appendevents, w3allAllowDomain);

 });
}
} // END if(window.self !== window.top){
</script>
<div data-iframe-size="" style="height:0;max-height:0;border:0;margin:0;padding:0;"><div>
<script type="text/javascript" src="https://forum.w3host.com/iframe-resizer.child.js"></script>
<!-- ENDIF -->

after adding this code to phpBB’s overall_footer.html, edit the following lines:

// START MANDATORY CHANGES

var w3allAllowDomain = 'https://w3host.com'; // MANDATORY! Set/Change this value to fit the absolute domain (DO NOT ADD/INCLUDE final slash here)
var wordpress_url_page_forum = 'https://w3host.com/forum'; // MANDATORY! (DO NOT ADD/INCLUDE final slash here) Url that point to the wordpress forum page
var w3all_custom_wp_w3fancyurl = 'w3'; // MANDATORY! If you changed the default 'w3' query string to use a fancy URL, update this value to match the fancy URL setting in the shortcode.

// END MANDATORY CHANGES


Change the w3allAllowDomain variable value to match your root WordPress URL.

Change the wordpress_url_page_forum variable value to match the WordPress page where the shortcode is displayed (using the same value as the wp_page_name shortcode parameter).

Change the w3all_custom_wp_w3fancyurl variable value to match the fancy_url shortcode parameter.

Now check this line into the added code:

<script type="text/javascript" src="https://forum.w3host.com/iframe-resizer.child.js"></script>

It should point to the iframe-resizer.child.js file that you will upload to your phpBB root folder (or another location of your choice). You can find this file in

/wp-content/plugins/wp-w3all-phpbb-integration/addons/iframeresizer/.

Use the full absolute URL (including http:// or https://, adjusted to match your site). This is mandatory, or the resizer will not work.

After editing, save and upload the modified overall_footer.html to your phpBB template folder, overwriting the original file. Next, upload iframe-resizer.child.js to your phpBB root folder (or your chosen location).

Then note that phpBB needs to recompile the template files, or your changes will not appear. Open the phpBB ACP and go to:

Server Configuration -> Load settings -> Recompile stale style components

Set this option to YES and save. Load the frontend once to check the result, and leave this setting enabled for now—especially if you also plan to add the redirect code to overall_header.html (which redirects direct phpBB URL requests to the embedded phpBB inside your WordPress page).

Once you have tested everything and confirmed it works properly, return to the ACP, set this option back to NO, and save. This step is required for phpBB to load and rebuild template changes, but it should always be set to NO on a live production site.

overall_header.html code

If you want to redirect all direct phpBB URL requests to your WordPress forum page, follow this step:

Open your phpBB template’s overall_header.html file in a text editor and add the following code right after the closing </title> tag:

<!-- IF not S_IS_BOT --><script>
// START MANDATORY CHANGES
var wordpress_url_page_f = 'https://subdomain.w3host.com/wordpress/forum'; // MANDATORY! // (DO NOT ADD/INCLUDE final slash here) Url that point to your iframed wordpress forum page
var w3all_custom_wp_w3fancyurl = 'w3' // MANDATORY! If you changed w3 to have 'fancy URL' query string for the WP page forum, then change this value to match what your fancy URL setting is after you changed it on plugin admin page
// END MANDATORY CHANGES

function w3all0Normalize_phpBBUrl(u){
	var bu = "{BOARD_URL}";
	w3allappend = "{BOARD_URL}"; 
 if ( /^https?/ig.exec(u) !== null ){ 
   phpbburl = u.split(bu);
	 w3allappend = phpbburl[1];
 } 
if(/^\W/ig.exec(w3allappend) !== null){
 	w3allappend = w3allappend.split(/^.+?(\w+.+)$/);
 	if(w3allappend[1]){
 		w3allappend = w3allappend[1];
 	}
 	if ( w3allappend[1] && w3allappend[1].charAt(0) == '/' ){
 		w3allappend = w3allappend[1].substr(1);
 	}
}
return w3allappend;
}
 
if ((window.self !== window.top) != true) {
  if(/adm\//ig.exec(window.location.href) === null){ // avoid x ACP 
  var w3all_r = window.location.href.replace(/sid=.+/gi, '');
 w3all_r = w3all0Normalize_phpBBUrl(w3all_r);
 if(/adm\/index\.php/ig.exec(w3all_r) == null){
  hrefEnc = window.btoa(unescape(encodeURIComponent(w3all_r)));
  href0 =  wordpress_url_page_f + '/?'+ w3all_custom_wp_w3fancyurl + '=' + hrefEnc;
  document.location.replace(href0);
 }
}}
// END force w3all redirect
</script>
<!-- ENDIF -->

Change the wordpress_url_page_f variable value to match the WordPress page where the shortcode is displayed (using the same value as the wp_page_name shortcode parameter).

Change the w3all_custom_wp_w3fancyurl variable value to match the fancy_url shortcode parameter.

NOTE: If you ever need to disable or edit the overall_header.html JavaScript code and you cannot access phpBB at its direct URL because it forces a redirect to your WordPress forum page (and “Recompile stale style components” has already been reset to NO simply disable JavaScript in your browser. This will stop the redirect so you can log in to the ACP, set “Recompile stale style components” back to YES, and apply your template changes.

IMPORTANT: Keep this tip in mind if you ever get locked out or have trouble logging in while “Recompile stale style components” is turned off.

If the iframe does not display and you see a “mixed content” or “insecure content” warning in your browser console, you can fix it by doing the following:

Open your WordPress theme’s header.php template file and add the following code just before the other tags:

<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">

Note that for testing purposes or any other reason, you can comment out the following line in the code added to overall_header.html

// document.location.replace(href0);

This way, direct requests to phpBB will no longer be forced or redirected to your WordPress page, while you can still open the WordPress forum page to view and test the embedded phpBB iframe. Remember that to apply template modifications, phpBB needs to recompile the template files.

💞

Your appreciation and support go here – Thank you!

Example:

[w3allphpbbiframe url_push="no" phpbb_default_url="https://www.axew3.com/w3/forums/viewtopic.php?t=774" wp_page_name="phpbb-wordpress-template-integration-iframe-v6" scroll_default="no"]

will show something like this:

axew3.com

Iframe resize library by: https://github.com/davidjbradshaw/iframe-resizer