Echo don´t work

Hi :slight_smile:
Maybe someone can help, I try to implement Advanced Customs Types to my wordpress page and I run in so many problems as I am completely new to PHP.
I try to implement this code,which apparently gives me a button with a link on my page. But the page turns blank, does anyone know why?
Thanks <3
echo ‘

’;
print_r(get_field(‘button’));
echo ‘
’;
die(); <?php $button = get_field('button'); ?>
         <a 
        role="button" class="download large button sites-button hide-for-small-only" 
        href="<?php echo $button['url']; ?>"
            target="<?php echo $button['target']; ?>">
            <?php echo $button['title']; ?>
  </a>

why die() in this example? die(); will stop execution of the script.

Hi John
Thank you for the quick response
This explanation was given:
"
Peter Charlton
vor 2 Monaten

I like that notion of using die(); to limit the output to just the precomposed element for inspecting the array."
If I get rid of the die … the page is working but the layout seems to be gone as well… and there is no button :frowning:

Hello Anja, i see what you’re doing there and yes that is normal to test output. I assumed that you are trying to see the button, which die(); will stop execution, so you will not see the button.

I notice that you have some mixed quotations in your echo statement.
try this (copy and paste with quotations):

echo 'alpha bravo charlie<br />';
print_r(get_field('button'));
echo 'hello? testing 123';
exit;

Thanks you very much !it works inseat of a white page i have now “hello? testing 123”
But all my other content is gone also the layout.
Can I integrate this echo function with the rest of my code?

Thanks for your help!

Hello Anja,

i suspect that you may have removed the get_header from the example, which means that the header field that contains the button will not be displayed. Just try it again as it is typed in the video - And i have taken a moment or two to type it for you.

<?php
  //echo '<pre>';
  //print_r(get_field('button'));
  //echo '</pre>';
  //exit;

  get_header();
?>

<header class="front-hero" role="banner">
  <div class="marketing">
    <div class="tagline">
      <h1><?php the_field('title'); ?></h1>
      <h4 class="subheader"><?php the_field('subtitle'); ?></h4>
      <?php
        $button = get_field('button');
      ?>
      <a href="<?php echo $button['url']; ?>">
      target="<?php echo $button['target']; ?>">
      <?php echo $button['title']; ?></a>
    </div>
  </div>
</header>

it may be best if you copy and paste my code example.

Meantime, i don’t know anything about wordpress. I program from scratch in the poorman’s editor (notepad.) I will not be of much help to you with wordpress related code but i think that the missing get_header is why you do not see your content.

let us know if it works for you and i hope that you have a pleasant day :slight_smile:

I still have the header line in my code:

<?php /* Template Name: Front */ echo '
'; print_r(get_field('button')); echo 'hello? testing 123'; exit; get_header(); ?>
<<?php the_field( 'bafog' ); ?> <?php $button = get_field('button'); ?> <?php echo $button['title']; ?>
	<div class="watch">
		<span id="stargazers"><a href="https://github.com/olefredrik/foundationpress">1.5k stargazers</a></span>
		<span id="twitter"><a href="https://twitter.com/olefredrik">@olefredrik</a></span>
	</div>
</div>

Hello Anja,

you haven’t commented the output test, so the exit; command will stop execution of the script. use two forward slashes to create a single-line comment in PHP:
https://www.php.net/manual/en/language.basic-syntax.comments.php

i also notice a loose less-than sign which needs to be removed.
please try the following code:

<?php /* Template Name: Front */

//echo '';
//print_r(get_field('button'));
//echo 'hello? testing 123';
//exit;

get_header();
?>

<?php the_field( 'bafog' ); ?>
<?php $button = get_field('button'); ?>
<?php echo $button['title']; ?>

<div class="watch">
  <span id="stargazers"><a href="https://github.com/olefredrik/foundationpress">1.5k stargazers</a></span>
  <span id="twitter"><a href="https://twitter.com/olefredrik">@olefredrik</a></span>
</div>

Thank you John you helped me a lot ! the layout is back but the button is still not displayed …

Good morning Anja,

if you are using the code that you have posted, then i don’t see the code for the button. Just add the original button code to the current code, unless you are trying to make a button out of your current links and you don’t remember how to do this from the video. I don’t use wordpress or any other cms, so i can remind you to follow the steps in the video. just replace the data in the video with the data from your links.

<a role="button" class="download large button sites-button hide-for-small-only" 
   href="<?php echo $button['url']; ?>"
   target="<?php echo $button['target']; ?>">
   <?php echo $button['title']; ?>
</a>

$button['url'] = https://github.com/olefredrik/foundationpress 
$button['target'] = _blank
$button['title'] = 1.5k stargazers

so using the Insert/Edit Link dialogue as depicted in the video:

URL: https://github.com/olefredrik/foundationpress
Link Text: 1.5k stargazers
click to open in new tab (target="_blank" [if checked], otherwise [default] target is _self [unchecked])

Thank you so much for your help :slight_smile:

1 Like
Sponsor our Newsletter | Privacy Policy | Terms of Service