Blog of King Software

Learn online with us in simple steps.


Created by Vicky Parekh on Date: 29/12/2020

To Share blog or Information over social media like facebook, twitter or linked in for degital marketing of your project in codeigniter, You need to follow following steps:


Step 1:   In your codeigniter project folder go to the folder application/view/layout/main_layout.php:

  • Open main_layout.php file.
  • In this file, in head section, add the following code:

<meta property="og:url" content=""/>
<meta property="og:image" content=""/>
<meta property="og:title" content="" />
<meta property="og:description" content="" />

  • For example, you can used array for calling in the files as below

<meta property="og:url" content="<?php if(isset($url) && !empty($url)){echo $url;}?>"/>
<meta property="og:image" content="<?php if(isset($img) && !empty($img)){echo $img;}?>"/>
<meta property="og:title" content="<?php if(isset($title) && !empty($title)){echo $title;}?>"/>
<meta property="og:description" content="<?php if(isset($meta_desc) && !empty($meta_desc)){echo $meta_desc;}?>"/>

STEP 2: To share information over social media, you need to add social media button or images on that webpage through which you want to share blog/information and using anchor tag give link to anchor tag.

  • In the folder application/view, go to the file which you want to share on social media and open it.
  • You can put anchor tag on social media icons, images. So go to social media code in the view file where you put your social anchor tag.
  • Put the following code as an example

<a id="facebook" href="<?php echo base_url()?>your_controller_page" class="fa fa-facebook border-icon rounded-icon" target="_blank""></a>

<a id="twitter" href="<?php echo base_url()?>your_controller_page" class="fa fa-twitter border-icon rounded-icon" target="_blank""></a>

<a id="Linkedin" href="<?php echo base_url()?>your_controller_page" class="fa fa-linkedin border-icon rounded-icon" target="_blank""></a>

STEP 3: Now go to the particular controller file in which you change the title, description, image and url to be share on social media.
  • Go to application/controllers folder and open related controller file from it.
  • Your normal controller file can contain code like below:

    class PAGE extends CI_Controller {
    public function index() {
    $data['page_name'] = "page";

  • Now put the codes of array that you put in main_layout.php file in first step. As given below:

    class PAGE extends CI_Controller {
    public function index() {
    $data['title']="page title";
    $data['meta_desc']="page description";
    $data['url'] = base_url("controller-page-name");
    $data['img'] = base_url("assets/images/xyz/page.jpg");
    $data['page_name'] = "view file page name";