Home / Admin / SEO Ready™ – ACF: Author Snippet
Duplicate Snippet

Embed Snippet on Your Site

SEO Ready™ – ACF: Author Snippet

Code Preview
php
<?php
// Basic author information
$author_id = get_the_author_meta('ID');
$author = [
    'givenname' => get_field('author_givenname', 'user_'.$author_id),
    'familyname' => get_field('author_familyname', 'user_'.$author_id),
    'middlename' => get_field('author_middlename', 'user_'.$author_id),
    'prefix' => get_field('author_prefix', 'user_'.$author_id),
    'suffix' => get_field('author_suffix', 'user_'.$author_id),
    'gender' => get_field('author_gender', 'user_'.$author_id),
    'description' => get_field('author_description', 'user_'.$author_id),
    'website' => get_field('author_website', 'user_'.$author_id)
];
// Contact information
$contact = [
    'type' => get_field('contact_type', 'user_'.$author_id),
    'email' => get_field('contact_email', 'user_'.$author_id),
    'phone' => get_field('contact_phone', 'user_'.$author_id),
    'languages' => [
        get_field('available_language_1', 'user_'.$author_id),
        get_field('available_language_2', 'user_'.$author_id)
    ]
];
// Professional details
$professional = [
    'jobtitle' => get_field('author_jobtitle', 'user_'.$author_id),
    'occupation' => get_field('author_occupation', 'user_'.$author_id),
    'skills' => get_field('author_skills', 'user_'.$author_id),
    'worksfor' => [
        'name' => get_field('author_worksfor', 'user_'.$author_id),
        'url' => get_field('author_worksfor_url', 'user_'.$author_id)
    ]
];
// Education and credentials
$education = [
    'institution' => get_field('education_institution', 'user_'.$author_id),
    'url' => get_field('education_url', 'user_'.$author_id),
    'credential' => [
        'name' => get_field('author_credential_name', 'user_'.$author_id),
        'url' => get_field('author_credential_url', 'user_'.$author_id),
        'description' => get_field('author_credential_description', 'user_'.$author_id)
    ]
];
// Knowledge and expertise
$expertise = [
    'knowsAbout' => [
        get_field('author_knowsabout', 'user_'.$author_id),
        get_field('author_knowsabout_2', 'user_'.$author_id),
        get_field('author_knowsabout_3', 'user_'.$author_id),
        get_field('author_knowsabout_4', 'user_'.$author_id),
        get_field('author_knowsabout_5', 'user_'.$author_id)
    ],
    'knowsLanguage' => get_field('author_knowslanguage', 'user_'.$author_id)
];
// Location and address
$address = [
    'street' => get_field('author_street', 'user_'.$author_id),
    'city' => get_field('author_city', 'user_'.$author_id),
    'state' => get_field('author_state', 'user_'.$author_id),
    'postal' => get_field('author_postal', 'user_'.$author_id),
    'country' => get_field('author_country', 'user_'.$author_id)
];
// Social media and external links
$social = [
    'facebook' => get_field('author_facebook', 'user_'.$author_id),
    'instagram' => get_field('author_instagram', 'user_'.$author_id),
    'twitter' => get_field('author_twitter', 'user_'.$author_id),
    'linkedin' => get_field('author_linkedin', 'user_'.$author_id),
    'youtube' => get_field('author_youtube', 'user_'.$author_id),
    'website' => get_field('author_website', 'user_'.$author_id)
];
// Organization membership
$organization = [
    'memberof' => get_field('author_memberof_org', 'user_'.$author_id),
    'org_url' => get_field('org_url', 'user_'.$author_id)
];
// Awards
$awards = [
    get_field('author_award_1', 'user_'.$author_id),
    get_field('author_award_2', 'user_'.$author_id)
];
// Image information
$image = [
    'url' => get_field('author_image_url', 'user_'.$author_id),
    'width' => get_field('image_width', 'user_'.$author_id),
    'height' => get_field('image_height', 'user_'.$author_id),
    'caption' => get_field('image_caption', 'user_'.$author_id)
];
// Register variables for RankMath
add_action('rank_math/vars/register_extra_replacements', function() {
    global $author, $professional, $organization;
    
    $variables = [
        'givenname' => [$author['givenname'], 'Author Given Name'],
        'familyname' => [$author['familyname'], 'Author Family Name'],
        'worksfor' => [$professional['worksfor']['name'], 'Author Works For'],
        'jobtitle' => [$professional['jobtitle'], 'Author Job Title'],
        'memberof' => [$organization['memberof'], 'Author Member Of Organization']
    ];
    foreach($variables as $key => $data) {
        rank_math_register_var_replacement(
            $key,
            [
                'name' => esc_html__($data[1], 'rank-math'),
                'description' => esc_html__($data[1], 'rank-math'),
                'variable' => $key
            ],
            function() use ($data) {
                return $data[0];
            }
        );
    }
});

Comments

Add a Comment