WordPress.org

Ready to get started?Download WordPress

Forums

Custom Content Type Manager
[resolved] Using shortcode in text area (13 posts)

  1. jumust
    Member
    Posted 2 years ago #

    Hi,
    I'm using some shortcodes that I created with a plugin to display few icons.

    I set up with CCTM some custom fields as text-area and the default output filter as None (raw)

    If I add all those shortcodes to the default editor of WordPress they display correctly the image but if I add them in the text-area of CCTM they show up with the shortcode.
    If I was not clear I'm adding here a screenshot http://screencast.com/t/4tuTAK9Vb

    Also if I push the button shortcode in the HTML editor it doesn't even work, only works with default WP editor

    Please advice as I set up many Custom fields with your plugin and now it's definitely necessary to use shortcode within them. I might want to ask you for a custom work if it was not included in your plugin as I think this option should be obvious.

    Thanks a lot!

    http://wordpress.org/extend/plugins/custom-content-type-manager/

  2. fireproofsocks
    Member
    Plugin Author

    Posted 2 years ago #

    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

  3. jumust
    Member
    Posted 2 years ago #

    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>'
    									 )
    								);
    							?>
  4. jumust
    Member
    Posted 2 years ago #

    @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!

  5. fireproofsocks
    Member
    Plugin Author

    Posted 2 years ago #

    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

  6. jumust
    Member
    Posted 2 years ago #

    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?

  7. fireproofsocks
    Member
    Plugin Author

    Posted 2 years ago #

    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>')
    	);
    ?>
  8. jumust
    Member
    Posted 2 years ago #

    Perfect it works thanks!

  9. pzula
    Member
    Posted 1 year ago #

    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!

  10. fireproofsocks
    Member
    Plugin Author

    Posted 1 year ago #

    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') ); ?>

  11. pzula
    Member
    Posted 1 year ago #

    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.

  12. pzula
    Member
    Posted 1 year ago #

    Is this because I need to define get_custom_field in my theme functions?

  13. fireproofsocks
    Member
    Plugin Author

    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic