Pergunta

I want to echo the following code, but its not working:

<?php
if ( is_page('residenz') ) 
{ echo '[nggallery id=12]'; } 
else if ( is_page('apartment-royal-ii') ) 
{ echo '[nggallery id=13]'; } 
else if ( is_page('apartment-royal-iii') ) 
{ echo '[nggallery id=14]'; } 
else if ( is_page('apartment-royal-iv') ) 
{ echo '[nggallery id=15]'; } 
else if ( is_page('apartment-royal-v') ) 
{ echo '[nggallery id=16]'; } 
else { echo '[nggallery id=11]'; } 
?>

I assume that the problem is in the square brackets.

How can I echo [nggallery id=11] for instance?

Some more info:

The code is executed in a wordpress widget.

This is how I modified the widgets to accept php:

add_filter('widget_text','execute_php',100);
function execute_php($html){
     if(strpos($html,"<"."?php")!==false){
          ob_start();
          eval("?".">".$html);
          $html=ob_get_contents();
          ob_end_clean();
     }
     return $html;
}

EDIT2:

I used this and it works:

<?php
if (1 == 1)
{?>
 [nggallery id=13]
<?php
}
?>
Foi útil?

Solução

Use following code for echo the data:

<?php
echo htmlentities('[nggallery id=12]');
?>

Outras dicas

Square brackets do not need to be escaped. I think that your conditions evaluate to false. See what is the output of the following statement:

var_dump(is_page['residenz'])
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top