0

We recently implemented a stock quote system, where a user can enter a stock symbol and it will return all sorts of financial values.

I have a template made up that displays the financial widgets, and when a user enters a ticker symbol it runs some JS with the callback url being my template. In this example, it is something like this.

https://www.stocktrades.ca/quote/?qm_symbol=AAPL

What my issue is, is the title is currently blank. When a user inputs a symbol, the page title in the browser is simply “Quote -” Instead, I want it to be “Quote – XXXX” with XXXX being the stock ticker they entered.

What is the easiest way to go about this? I know it’s probably really simple, but I am stumped

3
  • Easiest way would be to use the JS to update the title (probably a <h1>) with the same callback.
    – WebElaine
    Jun 29, 2018 at 14:04
  • Thanks for the reply! One issue I have, and I was thinking of doing it that way, is typically shouldn't the page title be generated before the page generates? Putting it in that JS may delay that.
    – Dan
    Jun 29, 2018 at 14:17
  • You should have a default - maybe "Your quote is loading" or something like that - then when you run the JS it can replace the title right as it displays the rest of the page.
    – WebElaine
    Jun 29, 2018 at 15:09

2 Answers 2

0

Your best bet may be to use existing WordPress filters to modify your page title. For your needs, the the_title() filter would probably be your best best.

Here's a link to a pretty good tutorial on using it.

0

So this is the code I ended up going with. Please let me know if there is anything wrong with this!

add_filter( 'the_title', 'ps_wp_title_quote' );
    function ps_wp_title_quote( $title )
    {
    if(isset($_GET['qm_symbol'])){
        $qm_symbol = $_GET['qm_symbol'];
    }
    if (is_page('quote') ) {
           $title = __( 'Stock Information For', 'textdomain' ) .' '. $qm_symbol;
    }
    return $title;
    }

the problem I am still having though is when I place this in the functions.php file, when I enter a quote symbol it changes my navigation menu items to the title from this filter as well. When I add it directly into Quote.php, it works fine.

Another problem I am having, is it still doesn't reflect the title in the browser tab. It still just says "Quote - ". Any way to fix this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.