How to add Twitter Card Code in the Header.php

Posted in: Newspaper
Post count: 31

I want to add Twitter Card to my website and when I try to enter the code in the header.php, the website goes blank without giving any error. This is the code I am trying to enter.
<?php
if(is_single() || is_page()) {
$twitter_url = get_permalink();
$twitter_title = get_the_title();
$twitter_desc = get_the_excerpt();
$twitter_thumbs = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), full );
$twitter_thumb = $twitter_thumbs[0];

$twitter_name = str_replace(‘@’, ”, get_the_author_meta(‘twitter’));
?>
<meta name=”twitter:card” value=”photo” />
<meta name=”twitter:url” value=”<?php echo $twitter_url; ?>” />
<meta name=”twitter:creator” content=”@username”/>
<meta name=”twitter:title” value=”<?php echo $twitter_title; ?>” />
<meta name=”twitter:description” value=”<?php echo $twitter_desc; ?>” />
<meta name=”twitter:image” value=”<?php echo $twitter_thumb; ?>” />
<meta name=”twitter:site” value=”@username” />
<?
if($twitter_name) {
?>
<meta name=”twitter:creator” value=”@<?php echo $twitter_name; ?>” />
<?
}
}
?></strong
Tell me what’s the solution. Please

Post count: 3343

Hello,
The code is not correct formatted.
Try this:

<?php
    if(is_single() || is_page()) {
    $twitter_url = get_permalink();
    $twitter_title = get_the_title();
    $twitter_desc = get_the_excerpt();
    $twitter_thumbs = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), full );
    $twitter_thumb = $twitter_thumbs[0];
    $twitter_name = str_replace('@','', get_the_author_meta('twitter'));
    ?>
    <meta name="twitter:card" value="photo" />
    <meta name="twitter:url" value="<?php echo $twitter_url; ?>" />
    <meta name="twitter:creator" content="@username"/>
    <meta name="twitter:title" value="<?php echo $twitter_title; ?>" />
    <meta name="twitter:description" value="<?php echo $twitter_desc; ?>" />
    <meta name="twitter:image" value="<?php echo $twitter_thumb; ?>" />
    <meta name="twitter:site" value="@username" />
    <?php
    if($twitter_name) {
        ?>
        <meta name="twitter:creator" value="@<?php echo $twitter_name; ?>" />
    <?php
    }
    }
    ?>

Use like here: http://screencast.com/t/fJzoOOi7

Post count: 31

Thanks, that solves my problem. I don’t know that formatting also works that way. Thanks a lot again. a great product you have and even great support.

Viewing 3 posts - 1 through 3 (of 3 total)
The forum ‘Newspaper’ is closed to new topics and replies.