0

I'm a little lost about where I can place a simple php echo within a loop.

I have a "program" taxonomy where each program is echoed onto buttons. Right now I'm only echoing the slugs for the link text. However, one of the taxonomies has two words, so naturally when I echo the slug, the hyphen appears.

Is there a way to easily remove the hyphen or create a variable like $program_title = get_the_program_name?

Code:

    $program_slug = get_the_program_slug($post);
    $program_names = get_terms('program', array('orderby' => 'names', 'fields' => 'all', 'hide_empty' => false)); 
    if ( $program_names && ! is_wp_error( $program_names ) ) {
        $program_slugs = array();
            foreach ( $program_names as $program_name ) {
                $program_slugs[] = $program_name->slug;
            }
    }

    <?php foreach ($program_slugs as $program_slug) { ?>
        <div class="button <?php echo $program_slug; ?>">
            <a href="<?php echo site_url() . '/' . $program_slug; ?>">
              <?php echo $program_slug; ?>
            </a>
        </div>
    <?php } ?>

Replacing the link text (the last $program_slug variable) with something like $program_title doesn't work.

  • get_the_program_slug() isn't a WordPress function, I would say, you have to show it, to get the help you want. – Nicolai Jul 28 '15 at 14:26
  • do you mean provide a screenshot? – timmyg Jul 29 '15 at 13:03
  • No, show the code. – Nicolai Jul 29 '15 at 13:07
  • My apologies; it's a custom function seen here on line 67 – timmyg Jul 29 '15 at 13:23

Your Answer

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

Browse other questions tagged or ask your own question.