• Rozwiązano ino-24

    (@ino-24)


    Witam.

    Pod każdym postem umieszczam przycisk „lubię to”. Kliknięcie rzeczywiście powoduje pojawienie się tego posta na Facebooku, jednak załączane jest losowe zdjęcie, nie związane w ogóle z tym postem. Jak można tego uniknąć? Proszę o odpowiedź (jeśli takowa istnieje).

    Pozdrawiam.

Viewing 1 replies (of 1 total)
  • Kuba Mikita

    (@kubitomakita)

    W nagłówku musisz dodać znacznik Facebook Graph. Polecam umieścić jednak w pliku functions.php szablonu taki kod:

    //Adding the Open Graph in the Language Attributes
    function add_opengraph_doctype( $output ) {
    		return $output . ' xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"';
    	}
    add_filter('language_attributes', 'add_opengraph_doctype');
    
    //Lets add Open Graph Meta Info
    
    function insert_fb_in_head() {
    	global $post;
    	if ( !is_singular()) //if it is not a post or a page
    		return;
            echo '<meta property="fb:admins" content="YOUR USER ID"/>';
            echo '<meta property="og:title" content="' . get_the_title() . '"/>';
            echo '<meta property="og:type" content="article"/>';
            echo '<meta property="og:url" content="' . get_permalink() . '"/>';
            echo '<meta property="og:site_name" content="Your Site NAME Goes HERE"/>';
    	if(!has_post_thumbnail( $post->ID )) { //the post does not have featured image, use a default image
    		$default_image="http://example.com/image.jpg"; //replace this with a default image on your server or an image in your media library
    		echo '<meta property="og:image" content="' . $default_image . '"/>';
    	}
    	else{
    		$thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'medium' );
    		echo '<meta property="og:image" content="' . esc_attr( $thumbnail_src[0] ) . '"/>';
    	}
    	echo "
    ";
    }
    add_action( 'wp_head', 'insert_fb_in_head', 5 );

    Sprawdza on czy strona jest postem i umieszcza w nagłówku potrzebne rzeczy.

Viewing 1 replies (of 1 total)
  • Temat ‘"Lubie to" pod postem – dziwny efekt’ jest zamknięty na nowe odpowiedzi.