Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

369
Visualizações
Right way for pass variable php to css in Wordpress

i need to passing variable from php to css for customize style from custom theme option.

The only way i have find is create file.css.php and working good.

But my question is: This is good for website load a file .css.php ? or can have some other problem, like speed or seo?

There are some other good methods? Thx

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Indirect solution:

It sounds like you want to include different CSS behavior based on user selection. Let's say that user selection is stored in a variable $foo. Just include it in an element's class like this

<?php 
$foo = 'option-1'; ?>
<div class="<?php echo $foo; ?>"></div>

There are also two direct solutions to your issue:

1. Use inline CSS or CSS in your file's page head:

<style>
  div.button { color:<?php echo $bar ?>; }
</style>

2. Use a PHP file as CSS. This would look like:

<link rel="stylesheet" type="text/css" href="/style.php">

Then you can use PHP variables right inside your CSS file. Just make sure you change the content-type back to CSS at the beginning of the file like this:

<?php header("Content-type: text/css; charset: UTF-8"); ?>

This method is a little bit unconventional, but it'll work without any speed or SEO drawbacks.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda