Add photo gallery to posts

Add photo gallery to posts

The CMSE Fields tool includes a robust image gallery function that will maximize and optimize your Joomla articles or any extension which output a ...

Notice: Undefined variable: slideshow in /home/cmsenerg/public_html/modules/mod_cmse_articles_latest/tmpl/_slideshow.php on line 223

Notice: Undefined variable: slideshow in /home/cmsenerg/public_html/modules/mod_cmse_articles_latest/tmpl/_slideshow.php on line 223
Add polls to articles

Add polls to articles

section cols2 col-wrap col Easily insert survey polls within articles or any extension. Create the poll with the CMSE Fields and insert into the ...

Notice: Undefined variable: slideshow in /home/cmsenerg/public_html/modules/mod_cmse_articles_latest/tmpl/_slideshow.php on line 223

Notice: Undefined variable: slideshow in /home/cmsenerg/public_html/modules/mod_cmse_articles_latest/tmpl/_slideshow.php on line 223
Add vote anywhere

Add vote anywhere

section cols2 col-wrap col Allow users to vote on any item. A user's IP address is tracked by a cookie so they can only vote once. Place the ...

Notice: Undefined variable: slideshow in /home/cmsenerg/public_html/modules/mod_cmse_articles_latest/tmpl/_slideshow.php on line 223

Notice: Undefined variable: slideshow in /home/cmsenerg/public_html/modules/mod_cmse_articles_latest/tmpl/_slideshow.php on line 223
Insert BandsInTown tour chart

Insert BandsInTown tour chart

Display tour charts from Bands In Town section cols2 col-wrap col bandsintown="Wallows|true|true|3|true" /col col /col /section

Notice: Undefined variable: slideshow in /home/cmsenerg/public_html/modules/mod_cmse_articles_latest/tmpl/_slideshow.php on line 223

Notice: Undefined variable: slideshow in /home/cmsenerg/public_html/modules/mod_cmse_articles_latest/tmpl/_slideshow.php on line 223
Add live chat to article

Add live chat to article

section cols2 col-wrap col Easily add a simple live chatroom to an article with the shortcode as chatroom by selecting the chat system ...

Notice: Undefined variable: slideshow in /home/cmsenerg/public_html/modules/mod_cmse_articles_latest/tmpl/_slideshow.php on line 223

Notice: Undefined variable: slideshow in /home/cmsenerg/public_html/modules/mod_cmse_articles_latest/tmpl/_slideshow.php on line 223

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
    <li>
    	<div class="paramLabel">
    		<label>Social Net Post Title</label>
    	</div>
    	<div class="paramValue">
    		<input type="text" name="socialtitle" value="<?php echo $this->row->socialtitle; ?>" />
    	</div>
    </li>
    


    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;
    }else{
        $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) ) {
        unset($document->_metaTags['name']['og:title']);
        $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 https://developers.facebook.com/tools/debug/og/object/

Copyright © 2020 CMSEnergizer.com. All Rights Reserved.
This website is powered by the Joomla!©™ 3 Website Framework | File download and article manager component by CMSE Custom Fields | Website hosting and development by WebsiteDons

CMSEnergizer.com is owned and operated by Emuzement Net Inc, Tampa, Florida USA