如何使用Drupal 7.x在“”中添加内容?

时间:2016-02-26 15:00:34

标签: php drupal drupal-7 head

我有很大的疑问...我是如何添加内容的(例如发布商google plus的链接,或元标记或外部资源css):

function mysubtheme_page_alter($page) {

$viewport = array(
    '#type' => 'html_tag',
     '#tag' => 'meta',
     '#attributes' => array(
         'name' =>  'viewport',
         'content' =>  'width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no')
 );
 drupal_add_html_head($viewport, 'viewport');


 $googleplus = array(
     '#type' => 'html_tag',
     '#tag' => 'link',
     '#attributes' => array(
        'href' =>  'https://plus.google.com/+google-plus',
        'rel' =>  'publisher')
 );
 drupal_add_html_head($googleplus, 'googleplus');


 $pinterest = array(
     '#type' => 'html_tag',
     '#tag' => 'meta',
     '#attributes' => array(
        'name' =>  'p:domain_verify',
        'content' =>  '7680eb52326ae9ee9e415d0ad')
 );
 drupal_add_html_head($pinterest, 'pinterest'); 


 $fontawesome = array(
     '#type' => 'html_tag',
     '#tag' => 'link',
     '#attributes' => array(
        'href' =>  '/sites/font-awesome.min.css',
        'rel' =>  'stylesheet')
 );
 drupal_add_html_head($fontawesome, 'fontawesome');
}

我希望你能帮助我:)对不起我的英语

编辑我问这也是因为这些是我最近的更改,现在我注意到如果我登录并查看我的网站Firefox,那就没有CSS了!荒诞!

现在我有三种方式:

  1. 不正确如何在head
  2. 中添加内容
  3. 问题Firefox(44.0.2)
  4. 问题模块ADVANCED CSS / JS AGGREGATION
  5. EDIT 2.0 这是firefox的一个问题(我重置它并解决了问题)...但是我想知道这种添加方式head是否正确; )

2 个答案:

答案 0 :(得分:0)

drupal_add_html_head将输出添加到HTML页面的HEAD标记。只要不发送标题,就可以调用此函数。

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

的更多信息

答案 1 :(得分:0)

我找到的最简单方法是在template.php中删除以下内容

    function THEMENAME_preprocess_html(&$variables) {
      if(drupal_is_front_page()) {
        $meta_description = array(
                '#type' => 'html_tag',
                '#tag' => 'meta',
                '#attributes' => array(
                    'name' => 'description',
                    'content' =>  'blah blah blah'
                )
        );
        $meta_keywords = array(
                '#type' => 'html_tag',
                '#tag' => 'meta',
                '#attributes' => array(
                    'name' => 'keywords',
                    'content' =>  'some, keywords'
                )
        );
        drupal_add_html_head( $meta_description, 'meta_description' );
        //drupal_add_html_head( $meta_keywords, 'meta_keywords' );

        drupal_add_html_head_link(array(
          'rel' => 'publisher',
          'href' => 'https://plus.google.com/xxxxxxxxx',
        ));
      }
    }

仅在头版页面上需要发布者,因此需要drupal_is_front_page