• Resolved Carl

    (@carlbtmn)


    I’m using the page link field type for one of the fields to use it as a button to a specific page. Is working fine in a query loop, but I don’t know how to change the (rel=”bookmark”) to say “View” or any text instead of the actual value.

    Is there a way to achieve this?

    Thank you.

Viewing 15 replies - 1 through 15 (of 27 total)
  • Plugin Author Phi Phan

    (@mr2p)

    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.

    Thread Starter Carl

    (@carlbtmn)

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

    ACF field = business_page

    Thread Starter Carl

    (@carlbtmn)

    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”.

    Thread Starter Carl

    (@carlbtmn)

    <a class="post-link"  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

    Plugin Author Phi Phan

    (@mr2p)

    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 year, 4 months ago by Phi Phan.
    Thread Starter Carl

    (@carlbtmn)

    It worked wonderfully. Thank you for your time.

    Plugin Author Phi Phan

    (@mr2p)

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

    Phi.

    Thread Starter Carl

    (@carlbtmn)

    Hello Phi Phan,

    Your previous solution worked as expected. I was wondering if I can do the same, but with an icon (SVG or FA) and replace the word “View”? I need this for another page.

    Thank you.

    Plugin Author Phi Phan

    (@mr2p)

    Hi @carlbtmn, You can use whatever you want for that purpose.

    Phi.

    Thread Starter Carl

    (@carlbtmn)

    Not sure I understand. I tried replacing the word “View” with the icon, but is not working.

    Plugin Author Phi Phan

    (@mr2p)

    @carlbtmn Please send me your code. I need to look at it to see the issue.

    Ah only inline tags can be nested inside the a tag, so make sure you don’t put a div or any block tags there.

    • This reply was modified 1 year, 2 months ago by Phi Phan.
    Thread Starter Carl

    (@carlbtmn)

    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 ( 'business_page' === $field_name && $block_content ) {
        $block_content = preg_replace( '/<a(.+?)>.+?<\\/a>/i',"<a$1><i class="um-faicon-list-alt"></i></a>", $block_content );
      }
    
      return $block_content;
    }, 10, 4);

    The error says:

    Syntax error, unexpected identifier “um”, expecting “)”.

    Plugin Author Phi Phan

    (@mr2p)

    @carlbtmn You have to change from <i class="um-faicon-list-alt"></i> to <i class='um-faicon-list-alt'></i>.

    It’s a syntax error. You put double quote inside double quote in a string.

    Thread Starter Carl

    (@carlbtmn)

    How did I miss that…

    I really appreciate your help. Thank you.

    Plugin Author Phi Phan

    (@mr2p)

    You’re welcome.

Viewing 15 replies - 1 through 15 (of 27 total)
  • The topic ‘Page Link’ is closed to new replies.