Can I add php code on title of a link? I have this problem: I created three content types. Actor, author and musician.
An user can modify own actor, author and musician profile, if his role is one of these.

A user can have more than one role, so, he can be actor, author and musician.
An actor can be a man or a woman, so his role canbe actor or actres.
In user menu I must have links on pages for these roles, so, an actor can have actor/[user:name] and an author can be author/[user:name].
Title of these links should be [user-name] actor or actres depending on the role.

Ok, I can use user-name token, but how can I retrieve the role?
Can I use php code on title of link?
Since you did not specify a version I am assuming Drupal 8, but the hooks are nearly the same for Drupal 7. (You can navigate to them from the linked documentation pages).

The problem is that a user can have multiple roles and they can be assigned in a random order. This way you can never be sure that the correct role is shown.

You could try to provide Drupal with some custom tokens for these roles. This means you'll have to create a small custom module, but that is really not that hard. 


Create a folder with your module name.
Create a &lt;modulename&gt;.info.yml file within that folder. (&lt;modulename&gt;.info for Drupal 7)
Create a &lt;modulename&gt;.module file within that folder. 


Then you'll have to implement 2 hooks in your .module file:

hook_token_info_alter(). This allows for the tokens to show up in the token browser.

hook_tokens_alter(). The code could look something like this:

function &lt;modulename&gt;_token_info_alter(&amp;$data) {
  // Add description of user tokens.
  $data['tokens']['user']['actor-role'] = array(
    'name' =&gt; t("Actor role"),
    'description' =&gt; t("Role if the user is an actor."),
  );
  $data['tokens']['user']['author-role'] = array(
    'name' =&gt; t("Author role"),
    'description' =&gt; t("Role if the user is an actor"),
  );

  // Add as much as you like (need).

}

function &lt;modulename&gt;_tokens_alter(array &amp;$replacements, array $context, \Drupal\Core\Render\BubbleableMetadata $bubbleable_metadata) {
  $options = $context['options'];

  if ($context['type'] == 'user' &amp;&amp; !empty($context['data']['user'])) {
    $user = $context['data']['user'];

    if (isset($context['tokens']['actor-role'])) {
      // PHP logic to determine the role. Below is an assumption and might not work.
      // Set the value to the actor-role token to 'Actor' or nothing.
      $actor-role = $user-&gt;hasRole('actor_role_id') ? t('Actor') : '';
      $actress-role = $user-&gt;hasRole('actress_role_id') ? t('Actress') : '';

      // Combine them (one should be empty leaving the other)
      $actor-role-to-show = $actor-role . $actress-role

      $title = $node-&gt;field_title-&gt;view('default');
      $replacements[$context['tokens']['actor-role']] = $actor-role-to-show;
    }

    // Again add as many as you like.
  }
}


Now you should be able to use [user:author-role] and any other tokens you have defined.