【问题标题】:Custom title attribute for WordPress stylesheetWordPress 样式表的自定义标题属性
【发布时间】:2016-12-28 21:18:30
【问题描述】:

如何在functions.php 文件中的wordpress 中为我自己的自定义样式表添加标题属性?我发现类似的东西 `

   global $wp_styles;
   $wp_styles->add('example-alt', '/themes/example/example-alt.css');
   $wp_styles->add_data('example-alt', 'title', 'Example Alternate Stylesheet');
   $wp_styles->add_data('example-alt', 'alt', TRUE);
   $wp_styles->enqueue(array('example-alt'));

` 但我不知道如何在 functions.php 文件或其他任何地方使用它?

【问题讨论】:

    标签: css wordpress themes stylesheet


    【解决方案1】:

    我不确定我是否理解了你的问题。您想为博客添加 CSS 样式表或为标题添加属性?

    如果你想在functions.php中添加一个CSS样式表,你必须像这样将它加入队列:

    如果您的 CSS 样式表名为“my-style.css”,请将其放在主题文件夹中的名为“css”的文件夹中,然后将其写入 functions.php:

    function your_theme_name_scripts() {
    
        // For Styles: 
        wp_enqueue_style( 'my-style', get_template_directory_uri(), '/css/my-style.css' );
    
        // For Scripts:
        wp_enqueue_script( 'my-script', get_template_directory_uri(), '/js/my-script.js' );
    
    }
    add_action( 'wp_enqueue_scripts', 'your_theme_name_scripts' );
    

    您可以在此处找到有关排队样式的更多信息:http://codex.wordpress.org/Function_Reference/wp_enqueue_script

    如果你想给标题添加任何属性,你有两种选择:在functions.php上创建一个过滤器,或者直接修改header.php上的wp_title()函数。第二种选择是最好的选择。 您可以在此处找到有关该标题的更多信息:http://codex.wordpress.org/Function_Reference/wp_title

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-11
      • 2018-04-20
      • 2015-01-23
      • 2011-12-12
      • 1970-01-01
      • 2018-05-08
      相关资源
      最近更新 更多