Skip to content

Instantly share code, notes, and snippets.

@rayrutjes
Created December 12, 2016 12:32
Show Gist options
  • Select an option

  • Save rayrutjes/d56f30fa0a094700e2149ca2b8e58b6d to your computer and use it in GitHub Desktop.

Select an option

Save rayrutjes/d56f30fa0a094700e2149ca2b8e58b6d to your computer and use it in GitHub Desktop.
This gist is useful for the Algolia plugin for WordPress when the backend URL is different from the frontend URL. Here we replace the `cms.` subdomain with the `www.` subdomain. After integrating this snippet in your code, you should trigger a full re-index.
<?php
/**
* @param array $shared_attributes
*
* @return array
*/
function custom_post_shared_attributes( array $shared_attributes ) {
$shared_attributes['permalink'] = str_replace( 'cms.', 'www.', $shared_attributes['permalink'] );
return $shared_attributes;
}
add_filter( 'algolia_post_shared_attributes', 'custom_post_shared_attributes' );
add_filter( 'algolia_searchable_post_shared_attributes', 'custom_post_shared_attributes' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment