dougan5772 2013-08-01 08:21
浏览 35
已采纳

Drupal SEO页面标题

I am trying to list a few games, each, on individual pages. While a game page is opened into a new window the head title of page (< title>) is set to games page header (< h1> My Game). Also to list all game types I am using quick tabs.

From 12 types of games only at 2 of them the title is settled correctly and my problem is that I don't know from where it comes. I have tried to var_dump() all the headers and all of them are returning the same thing "Game" not the title/heading from db.

Where should I look or what would be the next step ?

$metaTitle = $page['content']['metatags']['global']['title']['#attached']['metatag_set_preprocess_variable'][0][2];
$metaTitle = str_replace(' | SuperCasino.com', '', $metaTitle); 

Where should I look or what would be the next step ?

Here is my preprocess page code

function desktop_preprocess_page(&$vars, $hook) {
    if (isset($vars['node_title'])) {
        $vars['title'] = $vars['node_title'];
    }
    // Adding a class to #page in wireframe mode
    if (theme_get_setting('wireframe_mode')) {
        $vars['classes_array'][] = 'wireframe-mode';
    }
    // Adding classes wether #navigation is here or not
    if (!empty($vars['main_menu']) or !empty($vars['sub_menu'])) {
        $vars['classes_array'][] = 'with-navigation';
    }
    if (!empty($vars['secondary_menu'])) {
        $vars['classes_array'][] = 'with-subnav';
    }
    // Page template suggestions based off of content types
    if (isset($vars['theme_hook_suggestions']['node'])) {
        $vars['theme_hook_suggestions'][] = 'page__type__'. $vars['node']->type;
        $vars['theme_hook_suggestions'][] = "page__node__" . $vars['node']->nid;
    }

    // Add first/last classes to node listings about to be rendered.
    if (isset($vars['page']['content']['system_main']['nodes'])) {
        // All nids about to be loaded (without the #sorted attribute).
        $nids = element_children($vars['page']['content']['system_main']['nodes']);
        // Only add first/last classes if there is more than 1 node being rendered.
        if (count($nids) > 1) {
            $first_nid = reset($nids);
            $last_nid = end($nids);
            $first_node = $vars['page']['content']['system_main']['nodes'][$first_nid]['#node'];
            $first_node->classes_array = array('first');
            $last_node = $vars['page']['content']['system_main']['nodes'][$last_nid]['#node'];
            $last_node->classes_array = array('last');
        }
    }
    //var_dump($vars['theme_hook_suggestions']);die();

   // Page template suggestions based off URL alias
    if (module_exists('path')) {
        //$alias = drupal_get_path_alias(str_replace('/edit','',$_GET['q']));
        $alias = request_path();

        if ($alias != $_GET['q']) {
            //echo'here';die;
            $template_filename = 'page';
            foreach (explode('/', $alias) as $path_part) {
                $template_filename = $template_filename . '__' . str_replace('-','_',$path_part);
                $vars['theme_hook_suggestions'][] = $template_filename;
                //var_dump($template_filename);
            } 

        }
    }
  • 写回答

1条回答 默认 最新

  • duanheyi7147 2013-08-01 08:24
    关注

    You can use drupal_set_title(YOUR_TITLE) for the different pages.

        drupal_set_title($title = NULL, $output = CHECK_PLAIN)
    

    https://api.drupal.org/api/drupal/includes!bootstrap.inc/function/drupal_set_title/7

    From the theme level, you can use this code in your template.php:

    function MYTHEMENAME_preprocess_page(&$vars, $hook) {
        $vars['title'] = $custom_title';
        $vars['head_title'] = $custom_title;
    }
    

    For Drupal 7 its is : $vars['site_name']

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算