-
I’m hoping I can get some help making my custom variable previewable in the Meta Box Snippet Editor preview. The custom variable is working in the frontend. (But I need it to work in the backend too).
Here’s my code:
add_action( 'rank_math/vars/register_extra_replacements', function(){
rank_math_register_var_replacement(
'op_shortcode',
[
'name' => esc_html__( 'OP ACF Field', 'rank-math' ),
'description' => esc_html__( 'Custom ACF field from ACF shortcodes.', 'rank-math' ),
'variable' => 'op_shortcode(field-name)',
'example' => esc_html__( 'Custom field value', 'rank-math' ),
],
'get_op_shortcode_callback'
);
});
function get_op_shortcode_callback( $name, $post_id ) {global $post;
$post_id = "option"; // options page
$name = get_field( $name, $post_id, true );
return '' !== $name ? $name : null;
}
Screenshot of code: https://ibb.co/7CFqQK9
This says that it should work in the Meta Box Snippet Editor here: https://rankmath.com/kb/filters-hooks-api-developer/#add-extra-variables
This is what I’m seeing in the Meta Box Snippet Editor: https://ibb.co/YcBvRZY
Any help is appreciated!
The ticket ‘Custom variable preview not working in Meta Box Snippet Editor preview’ is closed to new replies.