2017-04-14 5 views
0

Ich habe eine Funktion in Wordpress, die überprüft, ob der Benutzer des Posts eine Facebook-ID dann das spezifische Meta-Tag mit dieser Facebook-ID hinzufügen, sonst wenn leer ist, dann ist es die voreingestellte Facebook-ID hinzufügen. Das Problem ist, dass, wenn der Benutzer des Posts eine Facebook-ID im Facebook-Bereich hat, die Funktion nur die Standard-Facebook-ID hinzufügt.Benutzerdefinierte Facebook-Autor-Tag wordpress

function facebook_author_tag() { 
 
    if (is_single()) { 
 
    global $post; 
 
    $author = (int) $post->post_author; 
 
    $facebook_url = the_author_meta('facebook_url'); 
 
    if (!empty($facebook_url)) 
 
\t { 
 
\t \t \t echo '<meta property="article:author" content="'. $facebook_url .'" />'; 
 
\t } else{ 
 
\t \t \t echo '<meta property="article:author" content="https://www.facebook.com/test" />'; 
 
    } 
 
    } 
 
} 
 
add_action('wp_head', 'facebook_author_tag', 8);

Und dieser Code ich die socials Felder auf der Seite des Benutzers einfügen verwendet.

function my_new_contactmethods($contactmethods) { 
 
// Add Twitter 
 
$contactmethods['twitter'] = 'Twitter'; 
 
//add Facebook 
 
$contactmethods['facebook'] = 'Facebook'; 
 

 

 
    
 
return $contactmethods; 
 
} 
 
add_filter('user_contactmethods','my_new_contactmethods',10,1);

Dank, wenn jemand mir helfen kann.

Antwort

0

Falls jemand dieses Problem haben dies war der Arbeitscode:

function facebook_author_tag() { 
if (is_single()) { 
    global $post; 
    $author = (int) $post->post_author; 
    $facebook_url = get_the_author_meta('facebook_url', $author); 
if (empty($facebook_url)) { 
    echo '<meta property="article:author"  content="https://www.facebook.com/test/"/><meta property="article:publisher" content="https://www.facebook.com/test/" />'; 

    } 
else{ 
    echo '<meta property="article:author" content="'. $facebook_url .'" /><meta property="article:publisher" content="https://www.facebook.com/test/" />'; 

    } 
    } 
} 
Verwandte Themen