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 ?

  • 1
    Add shortcode to header.php and remove it from your page. – Eugene Manuilov Feb 19 '13 at 6:28
  • My page.php displays contents by <?php the_content(); ?> function. So how can this be done, also I need to restrict only shortcodes of [orbit-slider] only – user7282 Feb 19 '13 at 6:36

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;
  • Thanks, this piece of code was the most suited for my requirement – user7282 Feb 19 '13 at 11:12

You can use the PHP call for a Shortcode. It works like this:

echo do_shortcode('[orbit-slider category="test"]');

But I think, from your question, that you may have different Shortcodes for each page. If this is the case, try adding a Custom Field for your Pages, containing the category for your Orbit-Slider.

Of course, if you use the build in Taxonomy System (e.g. the standard Categories) you do not have to use a Custom Field, you can just use the Category. I use the first Caategory for the Categoryversion - be sure to handle the exceptions yourself here.

// for the custom field version
$orbitcategory = get_post_meta( get_the_ID(), 'my_orbit_slider', true );
// for the Taxonomy version
$orbitcategory = get_the_category( get_the_ID() );
$orbitcategory = $orbitcategory[0]->name;

$thisslider = '[orbit-slider category="' . $orbitcategory . '"]';

echo do_shortcode( $thisslider );

You should be fine like this.

And remember to not put your shortcode into the Content again :)

  • My requirement was that I needed to add short code on content, but that shortcode should not appear on content, instead it should appear on the header part. – user7282 Feb 19 '13 at 11:13
  • Okay, didn't get it the first time. But a custom metabox would be the userfriendlier Version than inserting the Shortcode into the content an dnot displaying it there. – fischi Feb 19 '13 at 11:32
  • Thanks for that information,any good url for creation of custom metabox? – user7282 Feb 19 '13 at 12:18
  • I would start at the Codex Page, gives you a great overview and starting point for future Questions :) – fischi Feb 19 '13 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.