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
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">'));
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.