My blog now shares!

In my non-existent free time, I've decided to build myself a little blog. I enjoy writing, but don't generally have a lot of time to spend on it and, when I do, I sure don't want to have to worry about formatting. This has been a problem with WordPress sites I've worked on, so I was happy to discover that Anchor CMS uses Markdown, an easy tool that allows me to spend less time worrying about formatting and more time worrying about writing.

The one problem I've run into on Anchor, though, is that it didn't share well. I could post links to Facebook and Twitter, but everything showed up with the title "James Michiel" and my site's general description, not the title and description of the specific post or page that I was sharing. After a little digging and even a helpful Tweet from Anchor, I've mostly fixed it by adding the following code into my header.php file:

    <?php if(current_url() == "/" || current_url() == "posts") : ?>
        <meta property="og:url" content="http://www.jamesmichiel.com">
        <meta property="og:title" content="<?php echo site_name(); ?>">
        <meta property="og:description" content="<?php echo site_description(); ?>">
    <?php else: ?>
        <meta property="og:url" content="<?php echo "http://www.jamesmichiel.com" . current_url(); ?>">
        <meta property="og:title" content="<?php echo page_title('Page can’t be found'); ?> - <?php echo site_name(); ?>">
        <meta property="og:description" content="<?php if(strlen(article_description())) : echo article_description(); else: echo site_description(); endif; ?>">
    <?php endif; ?>

    <!-- Twitter card meta-->
    <meta name="twitter:card" content="summary" />
    <meta name="twitter:site" content="<?php echo site_name(); ?>" />
    <?php if(current_url() == "/" || current_url() == "posts") : ?>
        <meta name="twitter:title" content="<?php echo site_name(); ?>" />
        <meta name="twitter:description" content="<?php echo site_description(); ?>" />
        <meta name="twitter:image" content="" />
    <?php else: ?>
        <meta name="twitter:title" content="<?php echo page_title('Page can’t be found'); ?> - <?php echo site_name(); ?>" />
        <meta name="twitter:description" content="<?php if(strlen(article_description())) : echo article_description(); else: echo site_description(); endif; ?>" />
        <meta name="twitter:image" content="" />
    <?php endif; ?>`  

These sites were also helpful in figuring this out:

This article was posted by Jimi and is 159 words long.