Add alternative social network meta data to K2 posts

The facebook gods (or more like facebook assholes) have removed the ability to alter data scraped from pages, due to abusers who do so to mislead viewers. While there were evil doers wrecking the damn thing, there are good reasons why one would want the post title, text and even image to differ from the actual post.


Cases to alter social meta data

  • A post is considered NSFW (that's shorthand for the geek speak 'not safe for work') so Facebook puritans may punish you for it with bans. A softer image is needed for the post at FB and the title may need a few characters to make words only imply the meaning. So if the title and text includes 'fuck that dude', you will need to make it 'f&4k that dude' at the social spot.
  • A product post may literally state "My product is better than his" but you don't want to seem arrogant at the FB, so you want the title to read "Only the best is worthy for you"

...and so on.

The How to

Note that the excellent custom field system included with K2 will do the task very well, but this is about doing it with overrides and coding. This guide assumes you know how to use Joomla's template override system.

A default post will output at Facebook with the exact title and text as published with the page as the following image shows

before social meta alteration

After the modifications, the same post can be altered to output with title and text that differs from that of the page

new facebook scrape


  1. Create an override of administrator/components/com_k2/views/item/tmpl/default.php
  2. Edit the file at the line with string <h3><?php echo JText::_('K2_METADATA'); ?></h3>
  3. Add the block of code for the post title within the UL set. This will appear within the MetaData fieldset, above the meta description text area
    	<div class="paramLabel">
    		<label>Social Net Post Title</label>
    	<div class="paramValue">
    		<input type="text" name="socialtitle" value="<?php echo $this->row->socialtitle; ?>" />

    The output
    k2 social meta

  4. Alter the #__k2_items table to add the socialtitle column
    ALTER TABLE hex_k2_items
    ADD socialtitle VARCHAR(255) NOT NULL
  5. Create a K2 custom template by duplicating the default at components/com_k2/templates. Name the directory
  6. Edit item.php and add the following within the php block at the top
    $document = JFactory::getDocument();
    $metadesc = $document->getMetaData('description');
    if( !empty($this->item->metadesc) ) {
        $metadesc = $this->item->metadesc;
        $metadesc = strip_tags(substr($this->item->introtext, 0, 150));
    $document->setMetaData('og:description', $metadesc, 'property');
    // if social title is set, remove default title and write new title
    if( !empty($this->item->socialtitle) ) {
        $document->setMetaData('og:title', $this->item->socialtitle, 'property');
  7. Test


Note that you should always confirm the output by checking the FB scrape debugger at