This members-only tutorial provides the steps to register a custom “Is Archive” condition in Oxygen using which elements can be output (or not) only if the current page is an archive or not.

Step 1

Install and activate Code Snippets plugin.

Go to Snippets > Add New.

Title: [Condition] Is Archive?

Code:

if ( function_exists( 'oxygen_vsb_register_condition' ) ) {
	oxygen_vsb_register_condition(
		// Condition Name.
		'Is Archive?',

		// Values: The array of pre-set values the user can choose from.
		// Set the custom key's value to true to allow users to input custom values.
		array(
			'options' => array( 'true', 'false' ),
			'custom'  => false,
		),

		// Operators.
		array( '==' ),

		// Callback Function: Name of function that will be used to handle the condition.
		'wpdd_is_archive_callback',

		// Condition Category: Default ones are Archive, Author, Other, Post, User.
		'Other'
	);
}

/**
 * Callback function to handle the condition.
 *
 * @param  mixed  $value      Input value - true or false selected by the user.
 * @param  string $operator   Comparison operator, =.
 *
 * @return boolean              true or false.
 */
function wpdd_is_archive_callback( $value, $operator ) {
	return 'true' === $value ? is_archive() : ! is_archive();
}

Step 2

Apply the condition on the element(s) of your choice in the Oxygen editor.

The condition can be found under “Other” category.

Need help implementing a tutorial in your site or want to hire me for custom work?

HIRE ME

Find the article helpful and wish to donate?

DONATE

Comments

You need to be logged in to view and post comments.
Not a member yet? Join here.
magnifiercross
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram
%d bloggers like this: