A shortcode to change label text
-
Hi, great plugin, thank you for share!
I feel the labels “Before” and “After” are very poor options; if we could change them via shortcode would be a small but amazing improvement. Something like [twentytwenty before=”Old picture” after=”New picture”].
So I have just modified the plugin to add this feature. Here is my idea (snippet extracted from class-twentytwenty.php):
public function twentytwenty_shortcode( $atts, $content = null ) { /* my modification... */ extract(shortcode_atts( array( 'before' => '', 'after' => '' ), $atts) ); /* ...ends here */ wp_enqueue_script('jquery'); wp_enqueue_script('twentytwenty-jquery-event-move'); wp_enqueue_script('twentytwenty-twentytwenty'); wp_enqueue_script('twentytwenty-plugin-script'); wp_enqueue_style('twentytwenty-twentytwenty'); require_once( plugin_dir_path( __FILE__ ) . 'includes/smart-dom-document.php' ); $doc = new SmartDOMDocument(); $doc->LoadHTML($content); $images = $doc->getElementsByTagName('img'); $images_code = ''; $width = ''; $height = ''; foreach ($images as $image) { if($width == '') { $width = $image->getAttribute("width"); } if($height == '') { $height = $image->getAttribute("height"); } $images_code = $images_code . '<img src="' . $image->getAttribute("src") . '"/>'; } if ($width != '') { $width = $width . 'px'; } if ($height != '') { $height = $height . 'px'; } /* my modification: the style !important */ return '<div class="twentytwenty" class="twentytwenty-container" style="display: none; max-width: 100%; width: ' . $width . '; height: ' . $height . '">' . $images_code . '</div><style>.twentytwenty-before-label:before {content: "'. $before .'" !important; }.twentytwenty-after-label:before {content: "'. $after .'" !important; }</style>'; } }
It’s working good for me. Please feel free to add this if you want, I’m sure there are a lot of people who would like this feature.
Thank you again!
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘A shortcode to change label text’ is closed to new replies.