Get the correct page's title

Hi, I’ve been trying 2 methods and they both don’t work properly:

  1. using wixSeo:
import wixSeo from 'wix-seo';
let title = wixSeo.title; // "Page Title"
  1. using the $ selector:
let myTitle = $w("#myPage").title;  // "Page Title"

These methods doesn’t work if you’re in a specific blog post (I just get this value: “Post | MyWebsiteName”), or when using a lightbox (I get the lightbox’s name instead of the page I’m in).
I can’t seem to get the title that’s currently displayed in the browser’s tab unless I’m in a static page.

Any solutions?
Thanks in advance,

Hi there …

You should NOT use the page’s title property as it describes the structural name of the page (in the editor), instead, you should use the SEO’s title , and read it outside the page’s onReady( ) function.

Example:

import SEO from 'wix-seo';

const title = SEO.title;

$w.onReady(() => {
    // Run your page code here.
})

Hope this helps~!
Ahmad

Hi, as I said, I used both methods. None of them works.

@admin81489 can you please share the full code that you used to get the title and see that it’s incorrect?

@ahmadnasriya I did. Please see the original post.