i have several php pages want appear on wordpress site.
i'm using allow php in posts , pages plugin, , adding wordpress pages code such as:
[php]include $_server['document_root'] . '/brand_details.php';[/php]
i'm doing way because want solution portable possible (so i'd rather not edit functions.php, overwritten in next wordpress update), , want relatively non-technical wordpress folks can heads around.
it works reasonably pages, i'm struggling pages who's content depends on url parameter. in particular, i'm struggling set page title in situation.
for example, have page called brand_details.php displays details (name, address, website, etc.) of brands.
it's called url parameter, such ?brand_url=acehardware
from parameter, brand details in mysql table , display results.
this works ok, lose wordpress header , footer. around this, tried adding following code start , end of php page:
at start:
require $_server['document_root'] . '/wp-load.php'; get_header();
at end:
get_footer();
this kinda worked, although ran several styling issues - maybe that's theme i'm using (which divi).
but can't display brand name in page title. use example above, want display title such "ace hardware brand details". need change depending on brand that's selected.
so next step strip out code , try using wp_title filter instead. here's did:
i made copy of page.php in theme folder called page-custom.php
get_header();
call commented out , template name:custom inserted @ top.i made copy of header.php in theme folder called header-custom.php following line of code inserted
<head>
section:<?php add_filter( 'wp_title', 'set_custom_title' ); ?>
i added following code brand_details.php:
function set_custom_title($data) { return "$brand_name details page"; } get_header('custom');
i created wordpress page based on custom page template calls brand_details.php page.
what hoping happen page appear standard wordpress page, page title set according brand being displayed.
what happened wordpress header , footer appeared $brand_name variable mentioned above didn't used set_custom_title function, page title ended "details page" without brand name.
the (simplified readability) code brand name, before invoking function, follows:
$brand_url = $_request["brand_url"]; $sql = "select * brand_details brand_url = '$brand_url' limit 1"; $stmt = $db_conn->prepare($sql); $stmt->execute(array()); $row = $stmt->fetch(); $brand_name = $row['brand_name'];
i know works because use results in main page.
i've tried modifying last line read global $brand_name = $row['brand_name'];
in hope $brand_name variable becomes available in set_custom_title function, no avail.
i welcome advice on how achieve this, , i'm open alternative solutions job done.
i've solved this. here's how did it:
i created page template, based on divi theme's page.php, called page-brand_details.php , added code php page it. deleted
get_header();
start , added following code @ end:function set_custom_title($data) { global $brand_name; return $brand_name." brand details page"; } get_header('custom');
i created header template based on divi theme's header.php, called header-custom.php, replaced line
<title><?php elegant_titles(); ?></title>
following lines:<?php add_filter( 'wp_title', 'set_custom_title' ); ?> <title><?php wp_title(); ?></title>
- i created blank wordpress page using template created above.
Comments
Post a Comment