创建function.php(wordpress)

时间:2019-02-06 13:11:54

标签: javascript php wordpress

我第一次开发了自己的Wordpress主题。当我安装其他插件时,javascript无法正常工作。我不知道为什么。我的主题中还没有任何javascript文件,这就是为什么我未在functions.php中添加任何javascript文件。

add_theme_support('menus');

function register_theme_menus() {

    register_nav_menus(
        array(
            'primary-menu'  => __( 'Primary Menu', 'mymenu' )           
        )
    );

}

add_action( 'init', 'register_theme_menus' );


function wpt_theme_styles() {
    wp_enqueue_style( 'googlefont_css', 'http://fonts.googleapis.com/css?family=Asap:400,700,400italic,700italic' );
    wp_enqueue_style( 'main_css', get_template_directory_uri() . '/style.css' );

}

add_action( 'wp_enqueue_scripts', 'wpt_theme_styles' );


function twentysixteen_widgets_init() {
    register_sidebar( array(
        'name'          => __( 'Footer', 'twentysixteen' ),
        'id'            => 'sidebar-1',
        'description'   => __( 'Add widgets here to appear in your sidebar.', 'twentysixteen' ),
        'before_widget' => '<section id="%1$s" class="widget %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h2 class="widget-title">',
        'after_title'   => '</h2>',
    ) );
}

add_action( 'widgets_init', 'twentysixteen_widgets_init' );

1 个答案:

答案 0 :(得分:0)

您的问题是您缺少 wp_head()

示例header.php代码

<!DOCTYPE html>
<html <?php language_attributes(); ?> class="no-js no-svg">
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="profile" href="http://gmpg.org/xfn/11">


<?php 
    // This is what you are missing it is very important to include this in your header.php
    wp_head(); 
?>
</head>

参考: https://developer.wordpress.org/reference/functions/wp_head/

请务必阅读以上链接中页面末尾的评论。

快乐编码。