wpseo_register_var_replacement()Yoast 1.5.4

Register a new variable replacement.

This function is for use by other plugins/themes to easily add their own additional variables to replace. This function should be called from a function on the wpseo_register_extra_replacements hook. The use of this function is preferred over the older wpseo_replacements as a way to add new replacements. The wpseo_replacements should still be used to adjust standard WPSEO replacement values. The function can not be used to replace standard WPSEO replacement value functions and will thrown a warning if you accidently try. To avoid conflicts with variables registered by WPSEO and other themes/plugins, try and make the name of your variable unique. Variable names also can not start with "%%cf_" or "%%ct_" as these are reserved for the standard WPSEO variable variables 'cf_<custom-field-name>', 'ct_<custom-tax-name>' and 'ct_desc_<custom-tax-name>'. The replacement function will be passed the undelimited name (i.e. stripped of the %%) of the variable to replace in case you need it.

Example code:

function retrieve_var1_replacement( $var1 ) {
	   return 'your replacement value';

function register_my_plugin_extra_replacements() {
	   wpseo_register_var_replacement( '%%myvar1%%', 'retrieve_var1_replacement', 'advanced', 'this is a help text for myvar1' );
	   wpseo_register_var_replacement( 'myvar2', array( 'class', 'method_name' ), 'basic', 'this is a help text for myvar2' );
add_action( 'wpseo_register_extra_replacements', 'register_my_plugin_extra_replacements' );

Хуков нет.


true|false. Whether the replacement function was successfully registered.


wpseo_register_var_replacement( $replacevar_name, $replace_function, $type, $help_text );
$replacevar_name(строка) (обязательный)
The name of the variable to replace, i.e. '%%var%%'. Note: the surrounding %% are optional, name can only contain [A-Za-z0-9_-].
$replace_function(разное) (обязательный)
Function or method to call to retrieve the replacement value for the variable. Uses the same format as add_filter/add_action function parameter and should return the replacement value. DON'T echo it.
Type of variable: 'basic' or 'advanced'.
По умолчанию: 'advanced'
Help text to be added to the help tab for this variable.
По умолчанию: ''

Список изменений

С версии 1.5.4 Введена.

Код wpseo_register_var_replacement() Yoast 19.7.1

function wpseo_register_var_replacement( $replacevar_name, $replace_function, $type = 'advanced', $help_text = '' ) {
	return WPSEO_Replace_Vars::register_replacement( $replacevar_name, $replace_function, $type, $help_text );