小编Adr*_*chi的帖子

如何根据is_page()条件标记在Wordpress上为不同的页面排队多个css和js文件?

我是PHP/WordPress的新手,我在这里要做的是通过使用is_page()条件将不同的css和js文件排入不同的页面.

虽然我认为这是一个广泛讨论的话题,但我还没有找到一个简洁的方法来排队多个文件(css/js),然后设置is_page()条件,以便其中一些文件可以排入一个每个"不同的页面基础".

以下代码适用于我的主题,但是,我想知道是否有更好的方法来实现它.我真的很感激有关这个问题的一些指导.文本.

// To register my css styles I use the function below:

function enqueue_extra_styles()
{
wp_register_style( 'custom-style', get_stylesheet_directory_uri() . '/css/custom-style.css', array(), '1', 'all' );
wp_register_style( 'second-custom-style', get_stylesheet_directory_uri() . '/css/second-custom-style.css', array(), '1', 'all' );
wp_register_style( 'third-custom-style', get_stylesheet_directory_uri() . '/css/niceforms/third-custom-style.css', array(), '1', 'all' );

if ( is_page('8')) { 
//bellow styles will be enqueued only on a page of id=8

    wp_enqueue_style('custom-style');
    wp_enqueue_style( 'second-custom-style' ); 
  }

//bellow style will be enqueued only on a page of id=2111 

if ( is_page('2111')){ …
Run Code Online (Sandbox Code Playgroud)

php wordpress

2
推荐指数
1
解决办法
4257
查看次数

标签 统计

php ×1

wordpress ×1