All Collections
Developing with Shifter
Appending URLs to the artifacts
Appending URLs to the artifacts
Tomohyco Tsunoda avatar
Written by Tomohyco Tsunoda
Updated over a week ago

Shifter now supports appending URLs on your site.

How to apply

Insert following filter to functions.php on your theme.

Code

add_filter( 'ShifterURLS::AppendURLtoAll', 'my_append_urls' );

Limitations

  • URLs should be contained in WordPress (Shifter can't fetch external URLs)

  • URLs should be embedded in home_url("")

  • URLs should end with a slash (tailing slash) or allowed a listed suffix.

  • URLs will be generated with /index.html.

  • Content-Type will be same as what Shifter fetched from WordPress
    (e.g. /wp-json/wp/v2/posts/ will be /wp-json/wp/v2/posts/index.html and delivered as content-type: application/json.)

Allowed file suffixes

  • .html

  • .xml

  • .rss

  • .rdf

  • .atom

  • .css

  • .js

  • .json

Samples

Sample Code A

Adding /wp-json/wp/v2/posts/ to the target URLs of the generator

function my_append_urls( $urls ) {
$urls[] = home_url('/wp-json/wp/v2/posts/');
return $urls;
}
add_action( 'init', function(){
add_filter( 'ShifterURLS::AppendURLtoAll', 'my_append_urls' );
} );

Results A

/wp-json/wp/v2/posts/ ịs added to the target URL as "link_type": "from_filter_hook" and "path": "/wp-json/wp/v2/posts/".

$ curl -s https://127.0.0.1:8443/?urls | jq .

{
"datetime": "2020-07-07 02:41:39 UTC",
"page": null,
"start": 0,
"end": 100,
"limit": 100,
"items": [
{
"link_type": "home",
"post_type": "",
"link": "https://127.0.0.1:8443/",
"path": "/"
},

[... cropped ...]

{
"link_type": "from_filter_hook",
"post_type": "",
"link": "https://127.0.0.1:8443/wp-json/wp/v2/posts/",
"path": "/wp-json/wp/v2/posts/"
}
],
"request_type": "TOP",
"request_path": "/",
"count": 20,
"finished": true
}

Sample Code B

Appending the list of the stats of US as /states/($slag)/ to the target URL.

function my_append_urls( $urls ) {
$states = [
'Alabama',
'Arizona',

[...cropped....]

'Wisconsin',
'Wyoming',
];
foreach ( $states as $slag ) {
$urls[] = home_url("/states/{$slag}/");
}
return $urls;
}
add_action( 'init', function(){
add_filter( 'ShifterURLS::AppendURLtoAll', 'my_append_urls' );
} );

Sample Result B

$ curl -s https://127.0.0.1:8443/wp-json/shifter/v1/urls?page=1 | jq .
{
"datetime": "2020-09-04 06:01:58 UTC",
"page": 1,
"start": 100,
"end": 200,
"limit": 100,
"items": [
{
"link_type": "term_feed",
"post_type": "column",
"link": "https://127.0.0.1:8443/column/feed/",
"path": "/column/feed/"
},
:
{
"link_type": "from_filter_hook",
"post_type": "",
"link": "https://127.0.0.1:8443/states/Alabama/",
"path": "/states/Alabama/"
},
{
"link_type": "from_filter_hook",
"post_type": "",
"link": "https://127.0.0.1:8443/states/Arizona/",
"path": "/states/Arizona/"
},

[..... cropped .......]

{
"link_type": "from_filter_hook",
"post_type": "",
"link": "https://127.0.0.1:8443/states/Wisconsin/",
"path": "/states/Wisconsin/"
},
{
"link_type": "from_filter_hook",
"post_type": "",
"link": "https://127.0.0.1:8443/states/Wyoming/",
"path": "/states/Wyoming/"
}
],
"request_type": "TOP",
"request_path": "/",
"count": 91,
"finished": true
}

Did this answer your question?