Themes | WordPress

Replace A String With New String For All Posts In WordPress

April 19, 2014 / 145 views

Now WordPress is at version 3.9 and the new theme “Twenty Fourteen” is supposed to be the best free theme ever, but the theme does kill 2 of my plug-ins Mediabox Advanced and FancyBox 1.3.4. So, if I want to use Twenty Fourteen after I’m done modifying it, I have to replace the class strings of FancyBox with stings of FancyBox 2 and Mediabox Advanced with Slimbox 2.0.5 or ShadowBox.

FancyBox 1.3.4 I used ‘class=”ib”‘ for iFrames and FancyBox 2 ‘class=”ib2 fancybox.iframe” – To replace all posts that are using ‘class=”ib”‘ I need to edit the function.php of the “twenty fourteen” theme and add a function like this. This function will replace all posts with ‘class=”ib”‘ with ‘class=”ib2 fancybox.iframe”‘.

fancyboxstring

function replace_fancybox_to_fancybox2($content) {

       return str_replace(‘class=”ib”‘, ‘class=”ib2 fancybox.iframe”‘, $content);

    }

add_filter(‘the_content’, ‘replace_fancybox_to_fancybox2’);

One more way

function replace_ib($content)
{
$content = str_replace(‘class=”ib”‘, ‘class=”ib2 fancybox.iframe”‘,$content);
return $content;
}
add_filter(‘the_content’,’replace_ib’);

Paid Links

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.