In Shifter, you can add any URL to the list of URLs to be staticized by adding a filter to the theme’s functions.php to add any URL to the list of URLs to be staticized. Use this to add URLs that are not included in the normal staticization process, such as WordPress REST API endpoints or pagination URLs for custom post types.
How to Use
Add the following to functions.php:
function my_append_urls( $urls ) {
$urls[] = home_url('/path-to-add/');
return $urls;
}
add_filter( 'ShifterURLS::AppendURLtoAll', 'my_append_urls' );
Limitations
- The URL must exist within WordPress (external URLs cannot be retrieved).
- The URL must be generated using
home_url(). - The URL must end with a trailing slash or one of the following suffixes:
- The URL is generated as
/index.html. - The Content-Type will be the same as the one Shifter retrieved from WordPress (e.g., /wp-json/wp/v2/posts/ is served as content-type: application/json).
Allowed file suffixes:.html.xml.rss.rdf.atom.css.js.json
How to Verify Functionality
While WordPress is running, access the homepage URL with?urls,?urls=1,?urls=2 … appended to view the list of URLs to be staticized. URLs added via the filter are displayed as "link_type": "from_filter_hook".
curl -s https://your-site.on.getshifter.io/?urls | jq .
{
"items": [
{
"link_type": "from_filter_hook",
"post_type": "",
"link": "https://your-site.on.getshifter.io/wp-json/wp/v2/posts/",
"path": "/wp-json/wp/v2/posts/"
}
]
}
Sample Code
A. Add a REST API Endpoint
function my_append_urls( $urls ) {
$urls[] = home_url('/wp-json/wp/v2/posts/');
return $urls;
}
add_filter( 'ShifterURLS::AppendURLtoAll', 'my_append_urls' );
B. Adding Multiple URLs at Once
function my_append_urls( $urls ) {
$states = [
'Alabama',
'Arizona',
// ...
'Wisconsin',
'Wyoming',
];
foreach ( $states as $slug ) {
$urls[] = home_url("/states/{$slug}/");
}
return $urls;
}
add_filter( 'ShifterURLS::AppendURLtoAll', 'my_append_urls' );
C. Adding pagination URLs for custom post types
Since pagination URLs are not automatically included in the staticization process, generate and add them dynamically as shown below.
function my_append_urls( $urls ) {
$limit = get_option('posts_per_page');
$args = array(
'post_type' => 'product_service',
'post_status' => 'publish',
'posts_per_page' => -1,
'fields' => 'ids',
'no_found_rows' => true,
);
$the_query = new WP_Query($args);
if ($the_query->have_posts()) {
$last_page = ceil(count($the_query->posts) / $limit);
for ($i = 2; $i <= $last_page; $i++) {
$urls[] = home_url('/product_service/page/' . $i . '/');
}
}
return $urls;
}
add_filter( 'ShifterURLS::AppendURLtoAll', 'my_append_urls' );