• Resolved charliemcf

    (@charliemcf)


    Hi, I have slide captions in the form of ‘Author – Title’ and I need them to render such that the Title component is in italics. So for each slide I need to grab the caption, split it at the hyphen and wrap the Title in italics tags. Given the way that Metaslider works, what’s the best way to do this? I’m happy to do this at the individual slider level (flex, nivo etc) or for the meta data, whatever’s easiest. All advice very welcome, thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor kbatdorf

    (@kbat82)

    Hi @charliemcf

    Are you familiar with how hooks for in WP? You can hook into the image data before it’s presented. “metaslider_image_slide_attributes” is the one you would want to use.

    add_filter('metaslider_image_slide_attributes', function($slide, $slideshow_id) {
      $slide['caption'] = special_function($slide['caption']);
      return $slide;
    }, 10, 2);

    Let me know if that helps

    Hi @kbat82,

    Thanks for the excellent advice, very helpful. I understand the concept of hooks but haven’t used them before, good time to give it a go!

    Cheers, Clive

    Plugin Contributor kbatdorf

    (@kbat82)

    Hi @charliemcf,

    Let me know how it works out. I’ll mark this as resolved but feel free to comment again if you run into any issues.

    By the way, if you’re enjoying MetaSlider please leave us a 5-star review. They really help us out and let others find our plugin more easily. If you don’t think we deserve the 5 stars please let us know how we can improve, too. Thanks!

    https://wordpress.org/support/plugin/ml-slider/reviews#new-post

    Hi @kbat82,

    All good, many thanks. In the remote chance that this may help someone else, here’s the complete code:

    // Assuming caption in the form of 'Name - Title', this will italicise the title
    function split_caption($slidecaption) {
    $splitcaption = explode ("-", $slidecaption);
    $newcaption = $splitcaption[0] . "- <span style=\"font-style: italic\">" . $splitcaption[1] . "</span>";
    	return $newcaption;
    }
    
    add_filter('metaslider_image_slide_attributes', function($slide, $slideshow_id) {
      $slide['caption'] = split_caption($slide['caption']);
      return $slide;
    }, 10, 2);

    I just added this to the bottom of the child theme’s functions.php file.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Dynamic Editing of Slide Caption’ is closed to new replies.