Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option of changing of root url #107

Open
jibin2706 opened this issue Aug 2, 2021 · 5 comments
Open

Option of changing of root url #107

jibin2706 opened this issue Aug 2, 2021 · 5 comments
Labels

Comments

@jibin2706
Copy link

While generating the schema the root URL has the wordpress domain (wordpress.example.com). Is there a way to change the url to (blog.example.com)?

@github-actions
Copy link
Contributor

github-actions bot commented Sep 2, 2021

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

@github-actions github-actions bot added the Stale label Sep 2, 2021
@github-actions github-actions bot closed this as completed Sep 8, 2021
@jibin2706
Copy link
Author

not stale @ashhitch

@ashhitch ashhitch reopened this Sep 8, 2021
@ashhitch ashhitch added enhancement New feature or request and removed Stale labels Sep 8, 2021
@javialon26
Copy link

This is a nice to have feature, because the raw schema comes with WordPress base URL and we need to change to the front-end URL. I will try to change the URL with type.__all.beforeChangeNode function from gatsby-source-wordpress, another option can be the search-replace function but this changes the URL in the content also.

@Ririshi
Copy link

Ririshi commented Jan 18, 2023

I see this issue has been open for a while. Seems like something that (almost) everyone using this type of setup with GraphQL (i.e. headless WP) will need. I tried setting the WP_HOME but that also changes the address at which images and plugin files are accessed, which breaks a lot of other functionality.

Did anyone implement an elegant solution to this themselves? I'm thinking of adding a setting using a small extra plugin and using a search / replace to filter the url generated by Yoast.

@nicolawebdev
Copy link

Add this filter in WP:

add_filter('wpseo_schema_graph', function ($data) {
    $source = get_site_url();
    $target = '';
    switch (WP_ENV) {
        case 'development':
            $target = FE_SITEURL_DEV;
            break;
        case 'stage':
            $target = FE_SITEURL_STAGE;
            break;
        case 'production':
            $target = FE_SITEURL_PROD;
            break;
        default:
            $target = FE_SITEURL_PROD;
            break;
    }
    $data = deep_replace_array($source, $target, $data);
    return $data;
}, 10, 1);

function deep_replace_array($needle, $replacement, $subject)
{
    if (\is_array($subject)) {
        foreach ($subject as $key => $value) {
            if (\is_array($value)) {
                $subject[$key] = deep_replace_array($needle, $replacement, $subject[$key]);
            } elseif (\strpos($value, $needle) !== false) {
                $subject[$key] = \str_replace($needle, $replacement, $value);
            }
        }
    }
    return $subject;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants