0
votes

I need to parse a shortcode [ajaxdomainchecker].
I took action as below but it doesn't parse the shortcode, just shows a shortcode text.
(I tried the shortcode out of the acf field, it parses the shortcode.
$myvalue = get_field( "field_60f5d9a277654" ); echo do_shortcode($myvalue);
The problem: it doesn't directly parses the shortcode in an acf field.
The parsed code displays where the php code located.)

Would you please let me know how to parse the shortcode?

  1. Added a shortcode [ajaxdomainchecker] into Wysiwyg Editor field: enter image description here

2. Added the following code in a single post page, but shows a shortcode text:
$post = get_post();
echo do_shortcode(get_post_meta($post->ID, 'testsc', $single = true));

3. Added the following code in a functions.php, but shows a shortcode text:
function my_acf_format_value( $value, $post_id, $field ) {
    return do_shortcode( $value );
}
add_filter('acf/format_value/key=field_90f5c9a536352', 'my_acf_format_value', 10, 3);

enter image description here


Thank you.

1
Have you tried echo do_shortcode('[ajaxdomainchecker]') in a regular file? like front-page.php, could be that this shortcode doesn't even exist and thats why it returns the shortcode text - Buttered_Toast
Hi: Thank you for your comment. I tried it out of the acf field and it loads the shortcode. It just doesn't load in the acf field... - isbe
How is your textarea is set? you most likely have it as p or br for every new line, instead try to set it to no format or use plain text field - Buttered_Toast
Hi Buttered: Oh.. I looked into the acf field, but I couldn't find no fromat function. Should I set tabs to text only, then it will be no format? Would you please let me know how to set? - isbe
The formating for textarea is located in new lines, i could add a image if you want. if you still can't find it, try replacing textarea field into text - Buttered_Toast

1 Answers

0
votes
  1. WYSIWYG editor is the wrong choice for ACF field, change it to a Text field instead.
  2. Why use get_post_meta() when ACF comes with get_field()?

Try:

$my_shortcode = get_field('testsc');
if ($my_shortcode) {  
  $my_shortcode_content = do_shortcode($my_shortcode);
  if ($my_shortcode_content) {
    echo $my_shortcode_content);
  } else {
    echo 'Shortcode found, but is empty';
  }
} else {
  echo 'Unavailable';
}

if needed, you can add the post id as a second parameter to get_field(): https://www.advancedcustomfields.com/resources/get_field/