Change page title and description in a 1 page design

Difficult to explain what is wrong in the title, so hopefully its done enough to attract an expert.

I have a site that has been designed where there is a home page and it seems on clicking the categories that the design of the home page changes without refreshing, and so on through to the detail page of the clock.

So my problem is that the page titles and descriptions are all the same.

There is a template which is called titles.php which works fine when the pages refreshes, but its no good for the categories or the stock as you will see below:

$id = $_SERVER["REQUEST_URI"];

if ($id == "/the-w-f-bruce-story/") { ?>
<title>W.F. Bruce Antique Clocks | Est. 1985 | Member of British Antique Dealers Association &amp; Fellow of the British Horological Society.</title>
<meta name="description" content="W.F. Bruce Antique Clocks was established in 1985. A member of the  British Antique Dealers Association and a Fellow of the British Horological Society. We are one of the most interesting and varied Antique Clock specialists in the UK." />
<? } else if ($id == "/") { ?>
<title>W.F. Bruce Antique Clocks &amp; Barometers | Fine, Early, Stylish Antique Clocks | Longcase, Wall, Lantern, Mantel &amp; Other Clocks.</title>
<meta name="description" content="Antique Clocks &amp; Barometer Specialists | On-line Catalogue of Quality Antique Clocks including Longcase, Mantel, Lantern &amp; Wall Clocks For Sale. New Stock Added Daily." />
<? } ?>

This is the site to sorry, so you can see -

website link

I was thinking of looking out for the slug, but couldn’t work out how to do it, but will keep trying, but that’s not going to work for the stock as I need for the title and description of the stock to be used instead.

I have identified the code that creates the navbar, so I’m guessing I need to put a listener on the home page template, but again not sure.

<li>
<a class="<?php echo $term->slug; ?>" href="#" title="<?php printf ( __( 'View all items filed under %s', 'onioneye' ), $term->name ); ?>">
<span class="term-name"><?php echo $term->name; ?></span>
<!-- START .term-count -->
<span class="term-count"><?php echo $term->count; ?><span class="triangle-down"></span></span>
<!-- END .term-count -->
</a>
</li>

Tried at least to generate a bit of movement, but didn’t work.

<script>
$(document).ready(function() {
  $('.c-barometers').click(function() {
    alert("Hello How are you?");
});
</script>

and

var a = $("a.c-barometers");  

a.on("click", function(e) {
alert("Hello How are you?");
});

This is listening to the change in slug of the button class, and in this case just listening to the click of the ‘barometers’ button, but even if I got this working for the categories, I then got to think of something for the stock.

I have been working on this to try and work it all out, but I’m still struggling.
To check how the site looked within a ror.xml file I ran one off and although it seems to give a unique meta title to the stock items, the description is still always the same as there doesn’t seem to be a ‘description’ option for portfolio option, and I still have the issue of the categories not being seen.

To remind you this is the site enter link description here, and my problem is seen when you click ‘barometers’ and the page doesn’t refresh and I don’t get a new meta title or description, and I looked to find out what was controlling it all and I came across a page called titles.php and below is the code that is dealing with the whole meta content.

<?php
$id = $_SERVER["REQUEST_URI"];
if ($id == "/the-w-f-bruce-story/") { ?>
<title>W.F. Bruce Antique Clocks | Est. 1985 | Member of British Antique Dealers Association &amp; Fellow of the British Horological Society.</title>

<meta name="description" content="W.F. Bruce Antique Clocks was established in 1985. A member of the British Antique Dealers Association and a Fellow of the British Horological Society. We are one of the most interesting and varied Antique Clock specialists in the UK." />

<? } else if ($id == "/") { ?>

<title>W.F. Bruce Antique Clocks &amp; Barometers | Fine, Early, Stylish Antique Clocks | Longcase, Wall, Lantern, Mantel &amp; Other Clocks.</title>

<meta name="description" content="Antique Clocks &amp; Barometer Specialists | On-line Catalogue of Quality Antique Clocks including Longcase, Mantel, Lantern &amp; Wall Clocks For Sale. New Stock Added Daily." />

<? } else if ($id == "/links/") { ?>

<title>W.F. Bruce Antique Clocks | Links &amp; Resources for our Visitors and Customers.</title>

<meta name="description" content="W.F. Bruce Antique Clocks links page." />

<? } else if ($id == "/contact-us/") { ?>

<title>W.F. Bruce Antique Clocks &amp; Barometers | Lewes, East Sussex, London, UK.</title>

<meta name="description" content="W.F. Bruce Antiques are based in Lewes, East Sussex. We are open 9-5 Tuesday to Saturday and can also be contacted by phone or email regarding any Antique Clock or Barometer. Tel: 01273 473 123." />

<? } else if ($id == "/our-clocks/") { ?>

<title>W.F. Bruce Antique Clocks Specialists | International Reputation For 17th Century Restoration &amp; Conservation Work.</title>

<meta name="description" content="We are one of the leading antique clock specialists in the country, with an international reputation for our restoration and conservation work on pre-pendulum antique lantern and chamber clocks from the early 17th century." />

<? } else { ?>

<title><?php bloginfo( 'name' ); ?></title>

<meta name="description" content="<?php bloginfo( 'description' ); ?>" />

<? } ?>

But I cant for the life of me work out how to get the meta titles and descriptions to change when clicking the category buttons on the same nav bar as ‘barometers’ etc, I would be more than happy to allow people into the site if needed, but need some advice on this as I have dragged it on for a long time now.

I’m still on the issue, and have been thinking if someone wouldn’t mind helping me out with it, or at least tell me if its going to work.

The code below generates the nav bar

<?php if ( $count_terms > 0 ) { ?>
<?php foreach ( $terms as $term ) { ?>
<li>
<a class="<?php echo $term->slug; ?>" href="#" title="<?php printf ( __( 'View all items filed under %s', 'onioneye' ), $term->name ); ?>">
<span class="term-name"><?php echo $term->name; ?></span>
<!-- START .term-count -->
<span class="term-count"><?php echo $term->count; ?><span class="triangle-down"></span></span>
<!-- END .term-count -->
</a>
</li>                                                      
<?php } ?>
<?php } ?>

And I’m thinking that using jquery on click of the button I could change the meta title and meta description that way, so am going to try and work this out, but if there anyone that could point me in the right direction or set me off that would be great, or even if its going to work in the first place.

The class on the link - class=“<?php echo $term->slug; ?>” will be different for each category in the case of ‘Barometers’ it would be ‘c-barometers’, so those different class values will determine the meta title and meta description.

Something like this, but I’m wondering if it will work.

<title>Test</title>
<meta name="description" content="this is old">
<script type='text/javascript' src='http://code.jquery.com/jquery-1.8.2.js'></script>

<button>Change description</button>

<script type='text/javascript'>
$('button').on('click', function() {
// Just replacing the value of the 'content' attribute will not work.
$('meta[name=description]').remove();
$('head').append( '<meta name="description" content="this is new">' );
});
</script>

I have added this below to an include page, which works really well for the stock items, but for some reason not the categories, which is strange. But again I don’t know how to make it work for both the stock items and the category pages, I base this on what the ror.xml file contains.

    <title><?php bloginfo( 'name' ); ?></title>
    <meta name="description" content="<?php bloginfo( 'description' ); ?>" />

Thanks in advance if you help

Maybe there a way of better utilising the code below to grab the titles created in ‘portfolio’ which are the stock and the ‘categories’ also in Portfolio section to create the category nav buttons.

<title><?php bloginfo( 'name' ); ?></title>
<meta name="description" content="<?php bloginfo( 'description' ); ?>" />

So that it looks in both, but I’m not all that familiar with wordpress to replace ‘name’, with the ‘name’ and 'description within the ‘categories’ section as well as the ‘portfolio’ section which is whats happening above.

I thought I might be able to skip through the categories within portfolio and output the titles and descriptions that way, and so started with just trying to draw them out below, but doesn’t work by the look.

<?php $categories = get_terms("portfoliocategory");
foreach ($categories as $category) {
$entrycategory = str_replace(',','',str_replace('.','',$category->name));
echo '<a class="catlink" href="#filter=.'.$entrycategory .'"  rel="nofollow">'.$category->name.'</a>'; 
}?>

In the ror.xml file I can generate a page for the stock item, even though the page doesn’t refresh by using a url as below -

http://www.wfbruce.co.uk/portfolio/james-murray-domestic-regulator-london-c1815/ which then gives me -

<title>James Murray, Domestic Regulator, London, c1815</title>
 <description>Antique Clocks &amp;amp; Barometer Specialists | On-line Catalogue of Quality Antique Clocks including Longcase, Mantel, Lantern &amp;amp; Wall Clocks For Sale. New Stock Added Daily.</description>

This is generated in an include with the code below -

<title><?php bloginfo( 'category' ); ?></title>
<meta name="description" content="<?php bloginfo( 'description' ); ?>" />

So I thought I could get to the categores section by using something similar such as -

http://www.wfbruce.co.uk/categories/Barometers/

But doesn’t work that way by the looks

So I think maybe using if statements is the way, and found the array that holds all the categories which is below

<?php print_r(array_values($terms)); ?> 

This outputs this -

( [0] => stdClass Object ( [term_id] => 24 [name] => Archive [slug] => b-archive [term_group] => 0 [term_taxonomy_id] => 25 [taxonomy] => portfolio_categories [description] => [parent] => 0 [count] => 10 ) [1] => stdClass Object ( [term_id] => 5 [name] => Barometers [slug] => c-barometers [term_group] => 0 [term_taxonomy_id] => 5 [taxonomy] => portfolio_categories [description] => Antique Barometers East Susses, for sale and restored by WF Bruce. [parent] => 0 [count] => 8 ) [2] => stdClass Object ( [term_id] => 6 [name] => Bracket & Mantel Clocks [slug] => d-bracket-mantel-clocks [term_group] => 0 [term_taxonomy_id] => 6 [taxonomy] => portfolio_categories [description] => [parent] => 0 [count] => 6 ) [3] => stdClass Object ( [term_id] => 21 [name] => Lewes Clocks [slug] => f-lewes-clock-exhibition [term_group] => 0 [term_taxonomy_id] => 22 [taxonomy] => portfolio_categories [description] => [parent] => 0 [count] => 11 ) [4] => stdClass Object ( [term_id] => 8 [name] => Lantern Clocks [slug] => g-lantern-clocks [term_group] => 0 [term_taxonomy_id] => 8 [taxonomy] => portfolio_categories [description] => [parent] => 0 [count] => 4 ) [5] => stdClass Object ( [term_id] => 9 [name] => Longcase Clocks [slug] => h-longcase-clocks [term_group] => 0 [term_taxonomy_id] => 9 [taxonomy] => portfolio_categories [description] => [parent] => 0 [count] => 25 ) [6] => stdClass Object ( [term_id] => 25 [name] => Regulators [slug] => regulators [term_group] => 0 [term_taxonomy_id] => 26 [taxonomy] => portfolio_categories [description] => [parent] => 0 [count] => 3 ) [7] => stdClass Object ( [term_id] => 10 [name] => Wall Clocks [slug] => z-wall-clocks [term_group] => 0 [term_taxonomy_id] => 10 [taxonomy] => portfolio_categories [description] => [parent] => 0 [count] => 14 ) ) 

So how can I create an if statement using the above to ask something like this -

<?php if $terms == 'c-barometers' { ?>
<title> is this </title
<description>is this too </description>

That’s sort of Fred speak for what I think might work

I think I’m on the right track with below

$terms2 = get_terms( 'portfolio_categories', array('orderby' => 'name') ); 
<? } else if ($terms2->name == "Barometers") { ?>
<title>barometers.</title>
<meta name="description" content="Barometers." />
<? } else { ?>

Just the problem I got before I get to this is that the seperate categories pages arent producing their own pages that can be indexed, and havent a clue about that at the moment.

Be great if there a wordpress expert on here to give me some help.

Thanks

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.