Adding short codes from a page’s content on header and hiding the same from page’s content

I have created a page and added the following shortcode from wp-orbit-slider

 [orbit-slider category="test"] 

I want the contents of

 [orbit-slider category="test"] 

be displayed on the header part, instead of on the content area part, which the wordpress usually does . I tried adding the the short code on header.php and it works, but the same content will be duplicated on the content area also. I need to avoid this. How can this be achieved ?

2 Answers
2

This might work for you, trying to hook early to the_content filter to strip the shortcode tag from it:

add_filter('the_content', 'ad_filter_the_content',1,1);
function ad_filter_the_content($content) {
    // specify page id or array of page ids to include
    if (is_page(5)) {
        return str_replace('[orbit-slider category="test"]', '', $content);
    }
    return $content;
}

Leave a Comment