By default, WordPress parses shortcodes ONLY in the main content block. If you use shortcodes in your own WYSIWYG field (or anywhere else), you’ll need to use the “do_shortcode” filter: http://code.google.com/p/wordpress-custom-content-type-manager/wiki/do_shortcode_OutputFilter
Thread Starter
jumust
(@jumust)
Thanks!I’m trying to figure that out with the code I’m using. I built this piece of code basically with your suggestion at that time, now can’t understand how to edit it with the shortcode function, it’s breaking the page
<?php
print wpautop( get_custom_field('contatti:wrapper'
, '<div class="one_half" style="margin-bottom: 25px;">
<hr class="section" /><span class="tag_section">Contatti</span><hr class="section" /><div style="margin-top:25px;">[+content+]</div>
</div>'
)
);
?>
Thread Starter
jumust
(@jumust)
@fireproofsocks any idea what are the steps I need to get it working.
Now I can’t use shortcode in WYSIWYG field created with your plugin
What I wanna do is to have also text in the WYSIWYG and not only shortcode.
Thanks a lot!
By default, WordPress does not parse shortcodes anywhere EXCEPT in the main content block. You need to use the do_shortcode() function to parse shortcodes elsewhere. See the do_shortcode filter: http://code.google.com/p/wordpress-custom-content-type-manager/wiki/do_shortcode_OutputFilter
In your example, you’re using the “wrapper” output filter and some custom WordPress modifications… so it’s kinda a mess. Either use the CCTM’s output filter or use WP’s do_shortcode function: http://codex.wordpress.org/Function_Reference/do_shortcode
Thread Starter
jumust
(@jumust)
Thanks! I’m not expert and I built that code earlier asking in this forum suggestions because I don’t know how to write that code actually.
The thing I need is that the custom field disappear on the website if there is not content posted there in the admin, I remember maybe that someone told me to add print wpautop….so I don’t even know why I put it there.
Than I added my class and div, easier for me.
So what should I use to get shortcode working and make the field disappear if there is not content?
Do something like this:
<?php
print_custom_field('contatti:wrapper:do_shortcode'
, '<div style="margin-top:25px;">[+content+]</div>');
?>
You can chain output filters (see http://code.google.com/p/wordpress-custom-content-type-manager/wiki/OutputFilters) so I just added the do_shortcode filter after the wrapper filter.
Or if you wanted to use WP’s raw function:
<?php
do_shortcode(get_custom_field('contatti:wrapper'
, '<div style="margin-top:25px;">[+content+]</div>')
);
?>
Just curious as to how to get do_shortcode to work in my textarea (using the Editor option on Custom Content Type) the WP documentation on the subject is pretty sparse. I tried
<?php echo do_shortcode( 'ecpt_My_Field_Name' ) ?> to no avail.
Thank you!
WP’s do_shortcode function has caused me many headaches. But you need to run it on a string containing a shortcode, e.g.
<?php print do_shortcode( get_custom_field('my_custom_field') ); ?>
Is it possible for WP 3.4.2 to not understand get_custom_field? I feel like I have tried this and gotten an error that get_custom_field does not exist.
Is this because I need to define get_custom_field in my theme functions?
If you have installed CCTM and activated it, then that function gets defined. Its includes/functions.php file should be loaded during every page request. You can check whether it’s defined using function_exists: http://php.net/manual/en/function.function-exists.php
To debug your output, try printing the output of the function.