Jump to content

script to put seo stuff in head


DjordjeB

Recommended Posts

include "header.php";

if(isset($_GET['post_id'])) {
    $select=mysqli_query($con,"select....");
    while($data=mysqli_fetch_array($select)) {
         echo "bla bla bla";
         to_head("<title>asd</title><meta itemprop="name" content="asdfasdf">...");
    } 
}

include "footer.php";

This is samthing what i want... I have header.php and footer.php and any script ex news.php where how news and read SEO stuff from database and put in HEAD of the document. I tried with jquery like $("head").append(str); and it works but then i read google don't run jquery when vist website. 

 

This is done with drupal, wordpress and php-fusion

Drupal: https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_add_html_head/7

php-fusion: https://www.php-fusion.co.uk/forum/viewthread.php?thread_id=30959

 

so it is possible but i don't know how. Any idea?

Link to comment
https://forums.phpfreaks.com/topic/294184-script-to-put-seo-stuff-in-head/
Share on other sites

You need to add the stuff to the document before you output it. In your example, you are outputting the header and then attempting to add stuff to it afterwards....that's not going to work.

 

This sort of thing is easily done using template engines.

 

You could do something hacky like this:

<?php

function addHeader($elements) {
    include 'header.php';
}
header.php
<html>
<head>
<?php
    if (!empty($elements)) {
        foreach($elements as $element) {
            echo $element;
        }
    }
?>
</head>
usage
addHeader(array('<title>asd</title>', '<meta itemprop="name" content="asdfasdf">'));

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.