Welcome Guest, Not a member yet? Register   Sign In
Dynamic Meta Description
#1

(This post was last modified: 10-21-2017, 07:57 AM by ciadmin. Edit Reason: seo spam redacted )

Hello everyone, 
I hope this is the right section to ask this question. I'm building a Quiz Portal on CodeIgniter.
I've added meta description tag in the header view, but now that I've checked on Google, the same meta description is showing at all the pages indexed in Google. 
Can anyone please guide on how to show different meta descriptions, according to views or modules? 
Is there a library for that, or how to do it manually?

Would appreciate any help. 
Thanks
Reply
#2

Pass it to your different page views using the views $data array.

This way you can have it in the database and load it with the page.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(10-21-2017, 09:26 AM)InsiteFX Wrote: Pass it to your different page views using the views $data array.

This way you can have it in the database and load it with the page.

Hi 
I used layout view in CI4

how to do meta description, page title and so on?

can you kindly show me the code?
Reply
#4

(This post was last modified: 12-10-2020, 11:54 AM by InsiteFX.)

I create a data.php view in the vVews folder this is just a blank php file nothing in it.
It allows to have data for all the other views.

To use:

PHP Code:
$data = [
        'title'   => 'My title',
        'heading' => 'My Heading',
        'meta'    => 'My Meta',
];

echo 
view('_viewdata'$data);
echo 
view('your_layout_view'); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(12-10-2020, 07:50 AM)InsiteFX Wrote: I create a data.php view in the vVews folder this is just a blank php file nothing in it.
It allows to have data for all the other views.

To use:

PHP Code:
$data = [
        'title'   => 'My title',
        'heading' => 'My Heading',
        'meta'    => 'My Meta',
];

echo 
view('data'$data);
echo 
view('your_layout_view'); 

Thank you so much InsiteFX.

I am beginner to CI4 and PHP. is it possible to share folder you have worked. So I can understand better.
Reply
#6

There's really nothing to it, just create a _viewdata.php file in your Views folder with nothing in it.

PHP Code:
// the $data keys are the $title, $heading and $meta in the views.
// in the view where they are used. <?= $title;
?>
$data = [
        'title'   => 'My title',
        'heading' => 'My Heading',
        'meta'    => 'My Meta',
];

// Makes all the data global to all views.
echo view('_viewdata', $data);

// load your layout all the above data will be there.
echo view('your_layout_view'); 

That's all there is to it, you can also use the below in your layout's

PHP Code:
// you can also include other views in the layout like below
<?= view('_navbar'); ?>

<?= view('_sidebar'); ?>

It's very easy to do.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#7

(12-10-2020, 12:05 PM)InsiteFX Wrote: There's really nothing to it, just create a _viewdata.php file in your Views folder with nothing in it.

PHP Code:
// the $data keys are the $title, $heading and $meta in the views.
// in the view where they are used. <?= $title;
?>
$data = [
        'title'   => 'My title',
        'heading' => 'My Heading',
        'meta'    => 'My Meta',
];

// Makes all the data global to all views.
echo view('_viewdata', $data);

// load your layout all the above data will be there.
echo view('your_layout_view'); 

That's all there is to it, you can also use the below in your layout's

PHP Code:
// you can also include other views in the layout like below
<?= view('_navbar'); ?>

<?= view('_sidebar'); ?>

It's very easy to do.

Thank you so much. Appreciate. will try and let you know.
Reply
#8

(10-21-2017, 07:32 AM)shamzblueworld Wrote: Hello everyone, 
I hope this is the right section to ask this question. I'm building a Quiz Portal on CodeIgniter.
I've added meta description tag in the header view, but now that I've checked on Google, the same meta description is showing at all the pages indexed in Google. 
Can anyone please guide on how to show different meta descriptions, according to views or modules? 
Is there a library for that, or how to do it manually?

Would appreciate any help. 
Thanks


How did you solve that I am facing this issue
Codeigniter First, Codeigniter Then You!!
yekrinaDigitals

Reply




Theme © iAndrew 2016 - Forum software by © MyBB