0

i want to display a div on every single page, but not on the frontpage. For that i used the following code in the functions.php

 if (! is_front_page()) : 
   '<div class="button-kontakt"> <a href="/kontakt"><p>ANFRAGE</p></a></div>';
 endif; 

But my code is not working? The div is not shown. Somebody could help me with this?

best regards

Tom

1
  • Where do you want to show the div? It has to go somewhere in the templates. Commented Jul 20, 2017 at 14:08

2 Answers 2

1

You need to tell the PHP to echo the div.

if (! is_front_page()) : echo '<div class="button-kontakt"> <a href="/kontakt"><p>ANFRAGE</p></a></div>'; endif;

Unless you just want it on the top of the page, you need to add that code to a template file, not the functions file. If it is something that appears at the bottom of every page except the homepage, putting it in footer.php may be applicable.

Also, have you set the page you don't want to see it on as the front page via the option in the Appearance->Customise menu?

2
  • thanks! The problem was that i had the code in the functions.php. In the footer.php it worked! Why cant i put the code in the functions.php? Thanks man!
    – tom84
    Commented Jul 20, 2017 at 15:07
  • You can put the code in functions.php, but when it runs it won't pay any attention to templates, and will just appear at the top. Putting it in the header.php, footer.php or a tpl_*.php file gives you control over it's positioning.
    – James
    Commented Jul 20, 2017 at 15:15
0

Try this code:

 if ( ! is_front_page() && ! is_page( 'home' ) && ! is_home() ) : 
   echo '<div class="button-kontakt"> <a href="/kontakt"><p>ANFRAGE</p></a></div>';
 endif; 

or

 if ( ! is_front_page() && ! is_page( 'home' ) && ! is_home() ) : ?>
   <div class="button-kontakt"> <a href="/kontakt"><p>ANFRAGE</p></a></div>

<?php   endif; 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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