<a> with PHP within splits the link

I've finally found out how to call a the project-type in a link so the link changes depending on which page it shows.

This is the code:

    h3 class="widget-title"
a href="../"Terug naar ?php the_terms($post-ID, 'fluxus-project-type'); ?/a/h3

But what happens now is the following.

Both 'Terug naar' and the result from ID, 'fluxus-project-type'); ?> get split.

Example is found on the left side of the page at: http://www.jeroenbrugman.com/portfolio/schilderijen/sickert-als-jack/

Terug naar and Schilderijen are split in 2. How can I combine those so it's one link?

Thanks in advance!

Topic split php links Wordpress

Category Web


What you are doing isn't ever going to work the way you want. the_terms() is going to produce a list of complete a tags so you can't nest or merge it with another one like you are trying to do. And there are no convenient arguments or filters that would allow you to alter that link text. There are some not-so-convenient ones though. The simplest is a filter on get_the_terms

function prefix_term_name($terms, $post_id, $taxonomy ) {
  foreach ($terms as &$term) {
    $term->name = 'Terug naar '.$term->name;
  }
  return $terms;
}

Which you would use like:

?>
<h3 class="widget-title"><?php
  add_filter( 'get_the_terms','prefix_term_name',10,3);
  the_terms($post->ID, 'fluxus-project-type'); 
  remove_filter( 'get_the_terms','prefix_term_name',10,3); ?>
</h3><?php

The function definition itself can be in your functions.php file to keep things neat. }

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.