Insérer le code PHP dans WordPress Page et Post

Mots clés : phpwordpressphp

meilleur 3 Réponses Insérer le code PHP dans WordPress Page et Post

vote vote

100

function input_func( $atts ) {     extract( shortcode_atts( array(         'type' => 'text',         'name' => '',     ), $atts ) );      return '<input name="' . $name . '" id="' . $name . '" value="' . (isset($_GET\['from'\]) && $_GET\['from'\] ? $_GET\['from'\] : '') . '" type="' . $type . '" />'; } add_shortcode( 'input', 'input_func' ); 
vote vote

83

add_shortcode( 'SHORCODE_NAME', 'FUNCTION_NAME' ); 
function simple_function_1() {     return "Hello World!"; }  add_shortcode( 'own_shortcode1', 'simple_function_1' ); 
[own_shortcode1] 
Hello World! 
function simple_function_2() {     $output = "";          for ($number = 1; $number < 10; $number++) {             // Append numbers to the string         $output .= "$number<br>";     }           return "$output"; }  add_shortcode( 'own_shortcode2', 'simple_function_2' ); 
[own_shortcode2] 
1 2 3 4 5 6 7 8 9 
function simple_function_3($name) {     return "Hello $name"; }  add_shortcode( 'own_shortcode3', 'simple_function_3' ); 
[own_shortcode3 name="John"] 
Hello John 
[own_shortcode3] 
Hello  
vote vote

80

add_action('init', 'my_php_function'); function my_php_function() {     if (stripos($_SERVER['REQUEST_URI'], 'page-with-custom-php') !== false) {         // add desired php code here     } } 

Questions similaires