0

iam new with php and wordpress. i try to implement a shortcode which should only work for a specific slug for my website. all other sites should do another shortcode.

i tryed this:

<?php
if( is_page( ( 'azubi');
     <?php echo do_shortcode( '[contact-form-7 id="274"       title="Bewerbungsformular_beruf" ]' ); ?> 
else
     <?php echo do_shortcode( '[contact-form-7 id="2741"     title="Bewerbungsformular_berufe" ]' ); ?> 

 <?phpendif ?>

but with this i got an error. i thin php syntax is wrong? works this solution for that i want to have?

best regards tom

0

In this line if( is_page( ( 'azubi'); you start but not end the round bracket ["(" OR ")"] and not used semicolon after the if condition used colon like if( is_page('azubi')):

<?php
if( is_page('azubi')):
     echo do_shortcode( '[contact-form-7 id="274" title="Bewerbungsformular_beruf" ]' ); 
else:
     echo do_shortcode( '[contact-form-7 id="2741" title="Bewerbungsformular_berufe" ]' ); 

endif; 
?>

Check this : https://developer.wordpress.org/reference/functions/is_page/

Enter correct page name.

     if( is_page('About Us')):
                 echo do_shortcode('[contact-form-7 id="263" title="Contact form 1"]');
            else:
                 echo do_shortcode('[contact-form-7 id="264" title="Contact form 1_copy"]');

            endif;
  • thanks! no there is no php error anymore. but the code is not doing what he should. on all pages there is still the same contactform. but on the page /karriere/azubi there should be another one. Can you help me? – tom84 Mar 17 '17 at 11:03
  • I think you can wrong page title enter in is_page() because this code run in my setup. please check the updated answer. – Jignesh Patel Mar 17 '17 at 11:33
  • it works! thanks! i was in a custom post type and thatswhy i have to use is_single , thanks! – tom84 Mar 17 '17 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.