Hi Team,
I used the ACF on my site, on the category page I put the custom field description with wysiwyg. But Don’t know why suddenly the editor did not print the shortcode. For example i have shortcode [my_shortcode] typed on editor, but on the front end it showed [my_shortcode]. Anyone face this too?
Thanks
FYI: I am using pro vesion
Hi Beee,
Thanks for response, yes the shortcode registered. If I am using the standard WP WYSIWYG it worked. Any suggestions?
Thanks
Hi Beee,
Here my code:
/* Shortcode for additional product meta */
/* Shortcode for single product details */
function shortcode_product_title() {
global $product;
return $product->get_title();
}
add_shortcode('ouffice_product_title','shortcode_product_title');
function shortcode_product_cat() {
global $product;
$category = get_the_terms( $product->ID, 'product_cat' );
if ($category) {
return $category[0]->name;
} else {
return '<span style="color:red">[please input the category of this product]</span>';
}
}
add_shortcode('ouffice_product_cat','shortcode_product_cat');
function shortcode_product_brand() {
global $product;
//var_dump($product);
$brand = get_the_terms( $product->ID, 'product_brand' );
if ($brand) {
return $brand[0]->name;
} else {
return '<span style="color:red">[please input the brand of this product]</span>';
}
}
add_shortcode('ouffice_product_brand','shortcode_product_brand');
function shortcode_category_title() {
if ($term = get_queried_object()) {
$taxonomy = $term->taxonomy;
if ($taxonomy == "product_cat") {
return $term->name;
} else {
return 0;
}
}
}
add_shortcode('ouffice_category_title','shortcode_category_title');
That is just the shortcode definition. Do you also have the code where you retrieve the ACF values ?
What if you apply the filter ‘the_content’ to that output ?
Hi Beee,
Here the code to retrieve the field:
<?php
if ($term = get_queried_object()) {
$taxonomy = $term->taxonomy;
if ($taxonomy == "product_cat") {
echo get_field('custom_category_description', 'option');
}
}
?>
Where should I put ‘the_content’?
Thanks,
Forget that last part (for now).
I just did a test. I added a wysiwyg field to my taxonomy and added my shortcode, which is [home_url].
When I var_dumped this field as follows:
var_dump(get_field('content','{taxonomy}_{term_id}')); exit;
it gives me my home_url.
If I then echo it on my page it produces the same value.
And I didn’t apply any filter or do something extra. This is straight out of the box. So my first guess now is you have something activated (like a filter or so) which stops this shortcode from outputting.
Have you tested this with all plugins deactivated and on a default WP theme ?
I just realised that the default taxonomy description is also a wysiwyg editor (never realised this. I never use it).
Have you tried that as well ?
I probably completely overlooked it, but your syntax appears to be wrong.
You use
echo get_field('custom_category_description', 'option');
but you need to use
echo get_field('custom_category_description', {taxonomy}_{term_id});
So now I’m wondering why you get an output if this is the actual code, because your code retrieves an option field value and NOT a taxonomy description (or I’m not understanding your setup fully).
Try to changed in to
echo get_field('custom_category_description', {taxonomy}_{term_id});
But give the error 500, and also not working after disable all plugin, is it possible cause by WP upgrade, this happened after version upgraded
Just to be sure, you do understand, where it says {taxonomy}/{term_id} you have to replace it with ‘your variables’ ?
echo get_field('custom_category_description', category_categoryID );
The topic ‘Shortcode’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.