Reputation: 1
I'm looking to create dynamic titles via user input. We are a financial website, and we have a quoting feature where users can enter a ticker and it displays the financial information about the company. The page runs fine, but I'm struggling with the titles for SEO purposes and to avoid duplicates.
I have created a PHP template called "quote", which is what is executed if a user enters a ticker query. This is the code I have to generate the title:
<title><?php if(isset($_GET['qm_symbol'])){
$qm_symbol = $_GET['qm_symbol'];
}
if (is_page('quote') ) {
echo $qm_symbol.'- Stock Quote & Stock News For '.$qm_symbol;
}
?>
</title>
So, this works fine. It generates the titles as needed, and doesn't show anything on say a blog post where no input was placed. However, because I have the html outside of the PHP, it still generates a blank title tag and then below it the actual pages title tag generated by my theme.
For SEO purposes, I'd like to figure out how to code it so that if there is no user input, it doesn't output any title tags either. Any help on this? I imagine it is a simple solution, but I'm just struggling with getting the html integrated into the PHP. I imagine I cannot quote the echo statement, because it calls for the variable, being the ticker symbol.
Upvotes: 0
Views: 54
Reputation: 1702
//At the top of your page
$pageTitle = (isset($_GET['qm_symbol'])) ? $_GET['qm_symbol'] . " - whatever here" : "default title";
//In your head tag
<title><?= $pageTitle ?> </title>
Do something like this.
Upvotes: 1