[Resolved] Executing Shortcode from Tags

Home Forums Support Executing Shortcode from Tags

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #1172770
    Eric

    Hello,

    In WordPress, there are Pages, Post, Categories and Tags.

    The shortcode plugin (Shortcode) works with Pages and Post but not within Tags. Is there a way to make it work?

    I renamed tag to stock and the little snippet at the top is my editing and then the posts archive is listed afterwards.

    The plugin developer says that the theme has to enable shortcode execution with something like this: do_shortcode(‘the tag html’).

    Is this something I can make work with hooks? or in my child theme?

    Thanks,
    Eric

    #1172809
    Leo
    Staff
    Customer Support

    Hi there,

    Can you check with the developer to see what’s the code needed in order for it to work in a twenty series WP theme?

    My guess is that the same code would work in GP as those are WordPress’ core functions.

    #1172923
    Eric

    The plugin developer said that to have the shortcode execution in the “Description” of a tag, the theme developer needs to add the support. When you go to Tags and Add New, the description is where I would like the shortcode to work.

    The theme developer has to use the below function to execute shortcodes which are present in the description.
    https://developer.wordpress.org/reference/functions/do_shortcode/

    This may not be standard with wordpress to have shortcode run in the tag description but that’s something I would like to have.

    Do not that it was not working with my previous theme either. Just curious how I can make that happen.

    #1172939
    Leo
    Staff
    Customer Support

    GP does not control the category/tag description field as that’s all handled by WordPress.

    Can the plugin developer provide you with code that would work in a twenty series WP default theme? If so it should work in GP.

    You can also give this a shot:
    https://www.wpchunks.com/allow-html-in-category-description/

    #1176578
    Eric

    The plugin developer share this code. Seems pretty simple. Why is that not standard?

    Somewhere in your theme under inc/structure/archives.php in your child theme/parent theme.

    You should find a line something similar.

    printf( ‘

    %s

    ‘, $term_description ); // WPCS: XSS ok, sanitization ok.

    Replace $term_description with do_shortcode( $term_description )

    So it looks something like this

    printf( ‘

    %s

    ‘, do_shortcode( $term_description ) ); // WPCS: XSS ok, sanitization ok.

    Now the tag description should execute the shortcode.

    #1176662
    Leo
    Staff
    Customer Support

    It’s not standard as that field is handled by WordPress and that’s not standard for WordPress.

    Glad you found a solution 🙂

    #1176857
    Eric

    I am sorry, but it’s not true that it’s WordPress doing this.

    This is the code from your theme in the archive.php. Could you just not add the support for shortcodes?

    add_action( ‘generate_after_archive_title’, ‘generate_do_archive_description’ );
    /**
    * Output the archive description.
    *
    * @since 2.3
    */
    function generate_do_archive_description() {
    $term_description = term_description();

    if ( ! empty( $term_description ) ) {
    printf( ‘

    %s

    ‘, $term_description ); // WPCS: XSS ok, sanitization ok.
    }

    if ( get_the_author_meta( ‘description’ ) && is_author() ) {
    echo ‘

    ‘ . get_the_author_meta( ‘description’ ) . ‘

    ‘; // WPCS: XSS ok, sanitization ok.
    }

    /**
    * generate_after_archive_description hook.
    *
    * @since 0.1
    */
    do_action( ‘generate_after_archive_description’ );
    }

    #1176866
    Leo
    Staff
    Customer Support

    Just to confirm, you are talking about executing shortcodes in this field correct?
    https://www.screencast.com/t/AGBKR5LrGaxa

    Can you temporarily switch to a twenty series WordPress theme and see if shortcodes work in there?

    That is this function here:
    https://developer.wordpress.org/reference/functions/term_description/

    So if it works in twenty series theme, then it should work in GP.

    #1176879
    Eric

    Yes that’s the field in your image. I will try and see and get back to you.

    #1176890
    Leo
    Staff
    Customer Support

    Please do.

    Let me know 🙂

    #1176961
    Eric

    It’s the same.

    My question then is why would you not want to make that one improvement and support shortcode if you are going through the trouble of having a function that handles it?

    It seems that the concept is bothering you as opposed to see it as a shortcoming by wordpress and wanting to provide an improvement.

    #1176991
    Leo
    Staff
    Customer Support

    You would really have to ask this question to WordPress.

    Things like Categories and Tags are handled 100% by WordPress’ core functions.

    The theme itself doesn’t actually have the ability to alter those functionalities and it shouldn’t either.

    Therefore, when a plugin requires certain functionality to work (like executing in the description field), it’s up to the plugin author to actually make it work.

    GP can guarantee that if a plugin works with a default twenty series theme, then it will work with GP. Therefore if the plugin author can provide a method that works in a default twenty series theme, then the same method should work with GP.

    This is a very important standard for all WordPress themes. For example, let’s say GP alters the description field functionality to allow shortcode execution, then one day you decided to switch theme and the shortcode no longer works. I would think the better solution is for the plugin author to make it work with every theme, especially it needs to work with a default twenty series theme.

    I hope this provides some clarification.

    #1176993
    Leo
    Staff
    Customer Support

    You could try adding the filters in this article and see if that works for you:
    https://webgilde.com/en/shortcode-not-working-category-description/

    #1176995
    Eric

    I buy that. Thanks for explaining.

    #1176996
    Leo
    Staff
    Customer Support
Viewing 15 posts - 1 through 15 (of 17 total)
  • You must be logged in to reply to this topic.