2016-05-09 34 views
0

排隊動態CSS我一個入隊PHP文件讓我在travelify,子文件夾的functions.php dynamcis風格在WordPress沒有按牛逼工作

add_action('wp_enqueue_scripts', 'theme_enqueue_styles'); 

function theme_enqueue_styles() { 
wp_enqueue_style('parent-style', get_template_directory_uri() . '/style.css'); 
wp_enqueue_style('style_perso', get_stylesheet_directory_uri() . '/styleperso.php');} 

該文件是正確排隊,但它不冒這個PHP代碼

這是我styleperso.php短爲例

<?php 

header("Content-type: text/css; charset: UTF-8"); 
$newbgcolor ='red'; 
$newbgimage = 'none'; 

?> 
body.custom-background { 
background-color: <?php $newbgcolor ?>; 
background-image: <?php $newbgimage ?>; 
background-repeat: no-repeat; 
background-position: top right; 
background-attachment: fixed; 
background-size: cover; 
} 

我試圖把文件中的

require '/../../../wp-load.php'; 

但它沒有任何區別。

感謝您的幫助

+0

可能的答案[點擊這裏](https://css-tricks.com/ CSS-變量與 - PHP /#文章頭-ID-5)。 –

回答

0

使用AJAX來解決這個問題:

一般

function theme_enqueue_styles() { 
    wp_enqueue_style('dynamic-css', admin_url('admin-ajax.php') . '?action=dynamic_css', null, null); 
} 
add_action('wp_enqueue_scripts', 'theme_enqueue_styles'); 

function dynamic_css_action() { 
    include ('dynamic-css.php'); 
    exit; 
} 
add_action('wp_ajax_dynamic_css', 'dynamic_css_action'); 
add_action('wp_ajax_nopriv_dynamic_css', 'dynamic_css_action'); 

動態css.php

<?php 
    header('Pragma: public'); 
    header('Cache-Control: max-age=86400'); 
    header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 86400) . ' GMT'); 
    header('Content-Type: text/css; charset=UTF-8'); 

    $newbgcolor ='red'; 
    $newbgimage = 'none'; 
?> 
body.custom-background { 
    background-color: <?php echo $newbgcolor ?>; 
    background-image: <?php echo $newbgimage ?>; 
    background-repeat: no-repeat; 
    background-position: top right; 
    background-attachment: fixed; 
    background-size: cover; 
} 
+0

我嘗試了一切,但它看起來像wp_enqueue_style('dynamic-css',admin_url('admin-ajax.php')沒有完成。我檢查了它與wp_style_is,它沒有完成... !!!! _ – user3362083

+0

所以你可以檢查ajax請求是否工作,文件是否加載了'var_dump'?注意,對於ajax請求,你必須查看你的devtools中的網絡控制檯。 – kindisch

+0

過濾器標題發佈日期:星期三,1984年1月11日05:00: 00 GMT – user3362083