• Resolved KlaRo

    (@klaro)


    Hi,
    I have a very specific request. I am creating a complex website, where different (non-existing, would be 404 otherwise) URLs should display the same SEO data.

    For example I have a page called /example which normally exists in the backend and I have set up SEO data for it.

    My website however allows URLs like /info/example and /details/example (which do not really exist, I just supress the 404 and let them display the website anyway) which should display the same SEO data as for the original/parent /example page in the wp_head() call.

    Is there a function or a hook I can call before get_header() is called, perhaps to alter the $wp_query and trick WP/Yoast into thinking I am actually working with the original page?

    In essence, some pseudocode like yoast_get_page($id) or something like that.

    Thank you in advance for your answer!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter KlaRo

    (@klaro)

    Let me rephrase it, as my previous description might have been too complicated – is there a way to set SEO meta data for the 404 page, or alternatively a way to programatically display SEO meta data of another page (the homepage for example) on the 404 page, or any other page?

    I would like to avoid making dozen of action calls to wpseo_title, wpseo_metadesc, wpseo_opengraph_type, etc.

    By default, Yoast SEO already adds the necessary SEO meta data to the 404 error page. However, if you’d like to have something else, you can check our API page here. In addition, you can also check our GitHub repository to find the exact filter that suit your needs.

    Closed. No further questions.

    Thread Starter KlaRo

    (@klaro)

    In case anyone would like to do what I tried to do in the future, I simply used these (well documented filters) to override the Yoast data on certain pages:

      wpseo_title (retrieved data using _yoast_wpseo_title post meta)
      wpseo_metadesc (retrieved data using _yoast_wpseo_metadesc post meta)
      wpseo_robots
      wpseo_opengraph_url (constructed the URL I needed)
      wpseo_opengraph (used $GLOBALS[‘wpseo_og’]->image_output)

    In these filters, I used the WP is_404() function to check if I want to override or not.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Load SEO data by manually setting post ID?’ is closed to new replies.