Replace url for custom taxonomies for static site.
-
Have a static website on a different domain from the actual WP site. So replacing the URL for indices. The posts and other pages are fine however the taxonomies’ URLs are not being replaced with this code. Any help would be appreciated.
/** * Algolia URL Filter for use on a decoupled WordPress. */ class KB_Algolia_URL_Filter { const LIVE_URL = 'https://www.mywebsite.com'; /** * Class constructor. */ public function __construct() { add_filter( 'algolia_post_shared_attributes', array( $this, 'replace_url' ), 10, 1 ); add_filter( 'algolia_searchable_post_shared_attributes', array( $this, 'replace_url' ), 10, 1 ); } /** * Convert staging URL to live URL. * * @param array $shared_attributes from filter. * * @return array The array after replacement. */ public function replace_url( $shared_attributes ) { $live_url = self::LIVE_URL; $staging_url = site_url(); $shared_attributes['permalink'] = str_replace( $staging_url, $live_url, $shared_attributes['permalink'] ); $shared_attributes['images']['thumbnail']['url'] = str_replace( $staging_url, $live_url, $shared_attributes['images']['thumbnail']['url']); return $shared_attributes; } } new KB_Algolia_URL_Filter();
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Replace url for custom taxonomies for static site.’ is closed to new replies.