WordPress.org

Ready to get started?Download WordPress

Forums

Caption not Working with Shortcode (7 posts)

  1. inhouse
    Member
    Posted 3 years ago #

    Hello, I am using Shortcoder v2.3 plugin to enable me to use HTML that the WYSIWYG editor (nor my client) will not break. I am using it successfully in a couple areas of the site but these captions will not work when used in conjunction with shortcodes or if I place the code in a template file. Any idea what it is that breaks? The images come up, but the caption code displays on the page as well.

    <div class="four-seasons-img-link">[caption class="cap" align="alignnone" width="100" caption="Four Seasons"]<a class="events-img-link" title="Four Seasons Gallery" href="http://cobtree.com/new/photo-gallery/four-seasons-gallery/"><img class="events-img-link" title="Four Seasons Gallery" src="XXX" alt="Four Seasons Gallery" width="100" height="66" /></a>[/caption]</div>

  2. inhouse
    Member
    Posted 3 years ago #

    The preview doesn't even look right so I know it's not my CSS causing an issue. I place the same code in the page editor and it displays perfectly on the site, but then I use the shortcode instead and the caption displays funny. It's live here. The 5 images on top is the code placed in the page editor and the 5 below is how the shortcode displays the same code. Is it because of the brackets the captions use??

  3. Mike Thone
    Member
    Posted 3 years ago #

    The shortcode API only works by default when displayed with the_content, like when it's within the loop. This might be whats not working for you. To get shortcode to work outside the loop you need to use

    <?php echo do_shortcode('[yourshortcode]'); ?>

    So to get yours to work it should be something like this:

    <?php echo do_shortcode('
    [caption class="cap" align="alignnone" width="100" caption="Four Seasons"]<a class="events-img-link" title="Four Seasons Gallery" href="http://cobtree.com/new/photo-gallery/four-seasons-gallery/"><img class="events-img-link" title="Four Seasons Gallery" src="XXX" alt="Four Seasons Gallery" width="100" height="66" /></a>[/caption]
    '); ?>

    Basically, write the shortcode between the (' ').
    I hope this solves your issue.

  4. Mike Thone
    Member
    Posted 3 years ago #

    Oh, and do it in your actual .php file. the WYSIWYG editor doesn't allow the <?php --- ?> tags by default.

  5. inhouse
    Member
    Posted 3 years ago #

    @Mike - Shortcoder is a plugin that generates the shortcode for you. You write HTML in the plugin admin and place the shortcode in WYSIWYG. There's no need to use PHP in the template files with this plugin. I'm using shortcode so my client doesn't break my lengthy code in WYSIWYG. If you can, take a peek at Shortcoder. Makes it so you don't need template files and the shortcode can be placed multiple times throughout site if need be. So I think I still have a problem where my image code isn't jiving with the Shortcoder plugin. Don't know if its the caption brackets [ ] or what.

    Last resort would be to use more templates files but it is overkill for what I'm doing (placing 5 images in a page).

  6. Mike Thone
    Member
    Posted 3 years ago #

    I just took a look at the shortcoder plugin, and then checked back at your link. It looks like you fixed it. How did you get it to work?

  7. soccerplayersbase
    Member
    Posted 3 years ago #

    why not use jetpack? they have tons of shortcodes as i believe it's a plugin problem!

Topic Closed

This topic has been closed to new replies.

About this Topic