Wordpress Themes - WP Forum at BFA
There will be no more development for Atahualpa (or any other theme), and no support. Also no new registrations. I turned off the donation system. I may turn the forum to read only if it gets abused for spam. Unfortunately I have no time for the forum or the themes. Thanks a lot to the people who helped in all these years, especially Larry and of course: Paul. Take care and stay healthy -- Flynn, Atahualpa developer, Sep 2021

Wordpress Themes - WP Forum at BFA » WordPress Themes » Atahualpa 3 Wordpress theme » Header configuration & styling »

Change Title Tag based on parameter?


  #1  
Old Sep 8, 2016, 09:00 PM
Ob1knorrb
 
10 posts · Sep 2016
By default the title tag, which appears in the tabs in the browsers, gets set the Page Title and blog title, such as "Product_Page_test << ICEWEBRING". This is fine for most of my pages except for one.

In this one I change the content based on a parameter that is sent in (product_id), and I would like to change the Title Tag to be set to the second parameter (product_name)

Here is an example of this:

http://www.icewebring.com/ice-produc...ern%20Mirkwood

Before I moved my code to be within Wordpress, I was able to just include this in my php code:
echo "<title>$product_name</title>"

However, now that I've got the code within a Wordpress page, this no longer works, I think because I'm already out of the <head> area and into <body>.

I tried doing some Googling but didn't find a solution to this particular set of circumstances. The closest ones I found involved doing edits to header.php, which I'd like to avoid if possible.

Any suggestions on how to deal with this would be appreciated. Thanks!
  #2  
Old Sep 9, 2016, 06:50 AM
juggledad's Avatar
juggledad
 
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
Why not just name the page the product name? i.e. instead of calling the page 'Product_Page_test' call it 'Southern Mirkwood'?

Did you think about creating each product as a post instead of a page? That way each of the items
HTML Code:
Product Line: MERP
Product Edition: M1
Product Name: Southern Mirkwood
Product Type: Campaign Setting
Author: Susan Tyler Hitchcock
Stock #: 2700
ISBN: 0-915795-09-4
Publisher: ICE
Page Count: 60
Release Date: 1983
Language: English
could be a category allowing easy searching

or you could use a plugin like woocommerce.
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
  #3  
Old Sep 9, 2016, 07:36 AM
Ob1knorrb
 
10 posts · Sep 2016
The information about each book is in a database, there is a list page for each type of book (i.e. MERP, Rolemaster, Spacemaster) which reads the database for summary information. That page creates the links to the more detailed information pages for the individual books. It sends that page (now Product_Page) the product_id and product_title (was product_name).
Product_Page then uses product_id to load the rest of the information from the database and display the book. So it could be Southern Mirkwood, or it could be Northern Mirkwood, or any one of the other 600+ items in the database

http://www.icewebring.com/ice-produc...20Witch%20King

http://www.icewebring.com/ice-produc...tle=Arms%20Law
  #4  
Old Sep 9, 2016, 08:06 AM
juggledad's Avatar
juggledad
 
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
You may have set yourself a bit of a chore. I think the cleanest way for you to do this (depending on how you access your database) would be to create a custom plugin that hooks into wp-title() and based on the actual page you are on, substitutes the product name for the page name.

This way you are not changing any WP code (a really bad idea) and not changing the theme code and - if you decide to - if you change themes, the plugin should still work.

Or you could create a child theme and add code to function.php
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
Juggledad | Forum Moderator/Support
  #5  
Old Sep 9, 2016, 08:27 AM
Ob1knorrb
 
10 posts · Sep 2016
Thanks, that's what I was afraid of
At this point it's more of a "wish list" item rather than a "must have" so I'm going to file it as a to do list item.
The advantages of pulling that code into a Wordpress page with the Atahualpa theme definitely out weigh those of keeping it outside of Wordpress but trying to pull in the same header and menu items.
  #6  
Old Sep 9, 2016, 01:34 PM
Ob1knorrb
 
10 posts · Sep 2016
Is anyone aware of an existing plugin that might accomplish this or something similiar that I could look at as an example?
It looks like Yoast SEO might, but it also looks like it would be overkill for what I'm wanting to accomplish.
  #7  
Old Sep 10, 2016, 08:17 PM
Ob1knorrb
 
10 posts · Sep 2016
It turned out to be less difficult than I thought it might. Tacked some extra code into the Parameter.php addon that I previously bastardized to get the variables working.
I did need to turn off “Use Bytes for All SEO options” in “Configure SEO” in the “Atahualpa Theme Options”.
Here is the code I ended up with for the plugin in case anyone is interested, haven't adjusted the original author's information yet

<?php
/* Plugin Name: Parameter
Plugin URI: http://webopius.com/
Description: A plugin to allow parameters to be passed in the URL and recognized by WordPress
Author: Adam Boyse
Version: 1.0
Author URI: http://www.webopius.com/
*/
add_filter('query_vars', 'parameter_queryvars' );
function parameter_queryvars( $qvars )
{
$qvars[] = 'product_id';
$qvars[] = 'product_title';
return $qvars;
}

/*
* Uses product_title as page title if it exists
*/
function wpdocs_filter_wp_title( $title, $sep ) {

global $wp_query;
if (isset($wp_query->query_vars['product_title']))
{
$title=$wp_query->query_vars['product_title'];
}
return $title;
}
add_filter( 'wp_title', 'wpdocs_filter_wp_title', 10, 2 );
?>

Bookmarks



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Change Background Color based on Category Name tjwhitejr Center area post/pages 2 Jul 16, 2010 11:54 AM
[SOLVED] Width Parameter for New Widget Areas cab262 Sidebars & Widgets 2 Apr 12, 2010 12:13 PM
Change image based upon width haenchensd Header configuration & styling 1 Aug 3, 2009 04:21 PM


All times are GMT -6. The time now is 12:33 AM.


Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.