Filter uncanny-automator-pro

automator_loopable_rss_default_xpath

Filters the default XPath query used for parsing RSS feed items within the Loopable RSS integration.

add_filter( 'automator_loopable_rss_default_xpath', $callback, 10, 1 );

Description

Allows modification of the default XPath used by Loopable RSS to parse RSS feeds. Developers can provide a custom XPath string to target different elements within an RSS feed for Uncanny Automator. Defaults to '//channel/item' if the filter returns a non-scalar value.


Usage

add_filter( 'automator_loopable_rss_default_xpath', 'your_function_name', 10, 1 );

Parameters

$default_xpath (mixed)
This filter allows you to modify the default XPath query used for parsing RSS feeds.

Return Value

The filtered value.


Examples

<?php
/**
 * Change the default XPath for Loopable RSS items to target a custom feed structure.
 *
 * This filter hook allows developers to modify the default XPath query used by
 * Uncanny Automator's Loopable RSS integration. By default, it looks for
 * '//channel/item'. This example demonstrates how to change it to a different
 * path if the RSS feed has a non-standard structure.
 */
add_filter(
	'automator_loopable_rss_default_xpath',
	function ( $default_xpath ) {
		// Assume our custom RSS feed has articles nested under a different element,
		// for instance, '/feed/articles/article'.
		$custom_xpath = '/feed/articles/article';

		// Only apply the custom XPath if the provided default is the standard one,
		// to avoid overwriting another plugin's modification unintentionally.
		if ( $default_xpath === '//channel/item' ) {
			return $custom_xpath;
		}

		// If the default_xpath has already been modified by another filter,
		// we should respect that modification.
		return $default_xpath;
	},
	10, // Priority: Default WordPress priority
	1  // Accepted Args: The filter callback accepts only one argument ($default_xpath).
);
?>

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

uncanny-automator-pro/src/integrations/loopable-rss/helpers/loopable-rss-helpers.php:19

public static function get_default_rss_xpath() {

		$xpath = apply_filters( 'automator_loopable_rss_default_xpath', self::$default_xpath );

		if ( ! is_scalar( $xpath ) ) {
			return self::$default_xpath;
		}

		return (string) self::$default_xpath;
	}

Scroll to Top