Solution 4 - PHP String Extraction
Overview. This solution uses two PHP plugins to extract the content from the ugly page and put it into a pretty page.
- Ugly sidebar gets removed.
- Header and footer fill whole page.
- Pretty sidebar is properly aligned vertically.
- Uses no iframe. All content indexed by all search engines.
Disadvantages:
- Harder to do.
- Requires two PHP plugins.
Install and activate the
Code Snippets and the
Insert PHP plugins. Refer to
this thread for more about the PHP plugins used.
Make your ugly page, open it in a browser, and do a view source.
Find code at the end of the header, right before the content part of the page that you want to keep. Copy enough text from the end of that section that is unique and won't be anywhere else on the page. Don't copy anything that will change, like a date. For our example, we'll assume it's "
End of header code."
Find code at the beginning of the sidebar, right after the content part of the page that you want to keep. Copy enough text from the beginning of that section that is unique and won't be anywhere else on the page. Don't copy anything that will change, like a date. For our example, we'll assume it's "
Beginning of sidebar code."
These two lines of code should be the same for all pages made with the plugin. Check a few to be sure. (Bear in mind that future changes you make to your header or sidebar files might impact this function.) If you have access to these files, you could insert unique strings in them within comment tags such as:
HTML Code:
<!--EndOfHeader->
or
HTML Code:
<!--StartOfSidebar->
If you use such comment tags, include the tags in the snippet variables, so they don't get included in your extracted content.
Make and activate the following snippet (replacing "
End of header code." and "
Beginning of sidebar code." with the identifying codes you used):
PHP Code:
/**
* Extracts content of a page automatically generated
* by a plugin, removing unwanted parts.
* @param string $ugly_page_url url of page to be parsed
* @return string html code for extracted content
*/
function custom_extract_plugin_content($ugly_page_url)
{
$ugly_code = file_get_contents($ugly_page_url);
$header_ending_code = "End of header code.";
$sidebar_beginning_code = "Beginning of sidebar code.";
/* get starting and ending extraction points */
$start_point = strpos($ugly_code, $header_ending_code) + strlen($header_ending_code);
$end_point = strpos($ugly_code, $sidebar_beginning_code);
/* get length of string to be extracted */
$snip_length = $end_point - $start_point;
/* extract and return desired code */
$plugin_content = substr($ugly_code, $start_point, $snip_length);
return $plugin_content;
}
From your dashboard, make a new page, "pretty-page". Assign a template with the header, footer and pretty sidebar to this page. In the content area of that page, put the following:
HTML Code:
[insert_php]
echo custom_extract_plugin_content("http://yourdomain.com/ugly-page");
[/insert_php]