Page Link | WordPress.org

[ad_1]

Hello @carlbtmn

Thank you for your feedback. There is no setting to set the value for that rel attribute, however you can add a filter to change it like follows:

add_filter( 'meta_field_block_get_block_content', function ( $block_content, $attributes, $block, $post_id ) {
  $field_name = $attributes['fieldName'] ?? '';

  // Replace your_field_name with your unique name.
  if ( 'your_field_name' === $field_name ) {
    $block_content = str_replace('rel="bookmark"', 'rel="View"', $block_content);
  }

  return $block_content;
}, 10, 4);

Please customize it for your field and put it in the right place.

Thanks, Phi.

Is not working. Which fields do I need to change with the field name?

ACF field = business_page

Sorry it is working and the rel attribute changed, but I think I was not clear with my issue. I want to change what comes after the word “Example” with “View”.

rel=”View”>Example</a>

The value that shows up in the front-end is actually the end of the URL. I would like to keep the hyperlink, but change the word to say “View”.

<a class="post-link" href="https://website.com/example/" rel="bookmark">Example</a>

I think this is the best I can do to show what I mean. How can I change the text “Example” with “View” for all the posts in a loop.

Thank you!
-Carl

There are different methods to achieve this, but I think using regular expressions is a simple way as follows:

add_filter( 'meta_field_block_get_block_content', function ( $block_content, $attributes, $block, $post_id ) {
  $field_name = $attributes['fieldName'] ?? '';

  // Replace your_field_name with your unique name.
  if ( 'your_field_name' === $field_name && $block_content ) {
    $block_content = preg_replace( '/<a(.+?)>.+?<\\/a>/i',"<a$1>View</a>", $block_content );
  }

  return $block_content;
}, 10, 4);

Please test it with your field.

Thanks, Phi.

  • This reply was modified 1 hour, 39 minutes ago by Phi Phan.

It worked wonderfully. Thank you for your time.

@carlbtmn You’re welcome. I’m glad to hear that.

Phi.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer