Home / Admin / ACF: Author
Duplicate Snippet

Embed Snippet on Your Site

ACF: Author

Code Preview
php
<?php
// ACF custom variables
$knowsabout = get_field( 'author_knowsabout', 'user_'.get_the_author_meta( 'ID' ) );
$knowsabout2 = get_field( 'author_knowsabout_2', 'user_'.get_the_author_meta( 'ID' ) );
$knowsabout3 = get_field( 'author_knowsabout_3', 'user_'.get_the_author_meta( 'ID' ) );
$knowsabout4 = get_field( 'author_knowsabout_4', 'user_'.get_the_author_meta( 'ID' ) );
$knowsabout5 = get_field( 'author_knowsabout_5', 'user_'.get_the_author_meta( 'ID' ) );
$jobtitle = get_field( 'author_jobtitle', 'user_'.get_the_author_meta( 'ID' ) );
$alumniof = get_field( 'author_alumniof', 'user_'.get_the_author_meta( 'ID' ) );
// Rankmath custom variables
add_action( 'rank_math/vars/register_extra_replacements', 'register_extra_replacements' );
function register_extra_replacements() {
global $knowsabout;
rank_math_register_var_replacement(
'knowsabout',
array(
'name'        => esc_html__('Knows About', 'rank-math'),
'description' => esc_html__('Author Knows About', 'rank-math'),
'variable'    => 'knowsabout',
'example'     => 'knowsabout_callback()',
),
'knowsabout_callback'
);
global $knowsabout2;
rank_math_register_var_replacement(
'knowsabout2',
array(
'name'        => esc_html__('Knows About 2', 'rank-math'),
'description' => esc_html__('Author Knows About 2', 'rank-math'),
'variable'    => 'knowsabout2',
'example'     => 'knowsabout2_callback()',
),
'knowsabout2_callback'
);
global $knowsabout3;
rank_math_register_var_replacement(
'knowsabout3',
array(
'name'        => esc_html__('Knows About 3', 'rank-math'),
'description' => esc_html__('Author Knows About 3', 'rank-math'),
'variable'    => 'knowsabout3',
'example'     => 'knowsabout3_callback()',
),
'knowsabout3_callback'
);
global $knowsabout4;
rank_math_register_var_replacement(
'knowsabout4',
array(
'name'        => esc_html__('Knows About 4', 'rank-math'),
'description' => esc_html__('Author Knows About 4', 'rank-math'),
'variable'    => 'knowsabout4',
'example'     => 'knowsabout4_callback()',
),
'knowsabout4_callback'
);
global $knowsabout5;
rank_math_register_var_replacement(
'knowsabout5',
array(
'name'        => esc_html__('Knows About 5', 'rank-math'),
'description' => esc_html__('Author Knows About 5', 'rank-math'),
'variable'    => 'knowsabout5',
'example'     => 'knowsabout5_callback()',
),
'knowsabout5_callback'
);
global $jobtitle;
rank_math_register_var_replacement(
'jobtitle',
array(
'name'        => esc_html__('Job title', 'rank-math'),
'description' => esc_html__('Author Job title', 'rank-math'),
'variable'    => 'jobtitle',
'example'     => 'jobtitle_callback()',
),
'jobtitle_callback'
);
global $alumniof;
rank_math_register_var_replacement(
'alumniof',
array(
'name'        => esc_html__('Alumni Of', 'rank-math'),
'description' => esc_html__('Author Alumni Of', 'rank-math'),
'variable'    => 'alumniof',
'example'     => 'alumniof_callback()',
),
'alumniof_callback'
);
}
function knowsabout_callback() {
return get_field( 'author_knowsabout', 'user_'.get_the_author_meta( 'ID' ) );
}
function knowsabout2_callback() {
return get_field( 'author_knowsabout_2', 'user_'.get_the_author_meta( 'ID' ) );
}
function knowsabout3_callback() {
return get_field( 'author_knowsabout_3', 'user_'.get_the_author_meta( 'ID' ) );
}
function knowsabout4_callback() {
return get_field( 'author_knowsabout_4', 'user_'.get_the_author_meta( 'ID' ) );
}
function knowsabout5_callback() {
return get_field( 'author_knowsabout_5', 'user_'.get_the_author_meta( 'ID' ) );
}
function jobtitle_callback() {
return get_field( 'author_jobtitle', 'user_'.get_the_author_meta( 'ID' ) );
}
function alumniof_callback() {
return get_field( 'author_alumniof', 'user_'.get_the_author_meta( 'ID' ) );
}

Comments

Add a Comment