ThemeShaper Forums » Thematic

[closed]

Adding Smoothslider in #header with shortcode in functions.php?

(7 posts)
  • Started 11 years ago by elderberry
  • Latest reply from Danieliser
  • This topic is resolved
  1. elderberry
    Member

    Hopeless with php, so any help would be appreciated.

    This shortcode example does not work, it only displays the shortcode:
    // add slider in the header
    function show_slider() {
    return "[smoothslider id=1]";
    }
    add_action('thematic_header','show_slider');

    Nor does this work:
    // add slider in the header
    function show_slider() {
    if ( function_exists( 'get_smooth_slider' ) ) {
    get_smooth_slider(); }
    }
    add_action('thematic_header','show_slider');

    Plugin usage details http://www.clickonf5.org/smooth-slider

    Thanks!

    Posted 11 years ago #
  2. elderberry
    Member

    I added this to the header.php and it works, but I really prefer to do this the correct way...
    <div id="slider"><?php echo do_shortcode('[smoothslider id=1]'); ?></div>
    </div><!-- #header-->

    Posted 11 years ago #
  3. Danieliser
    Member

    Your on the right track.
    Try this.
    // add slider in the header
    function show_slider() {
    return do_shortcode('[smoothslider id=1]') ;
    }
    add_action('thematic_header','show_slider',0);

    Posted 11 years ago #
  4. elderberry
    Member

    @Danieliser thanks, but that did not work. I wonder if it is a problem with the plugin?

    Posted 11 years ago #
  5. Danieliser
    Member

    try this instead

    // add slider in the header
    function show_slider() {
      echo do_shortcode('[smoothslider id=1]') ;
    }
    add_action('thematic_header','show_slider',0);

    You might have to change the 0 at the end to adjust where in the header the code is inserted, as well as might be a good idea to add a container to it by echoing <div> inside the function around your shortcode and giving it a class so you can style it.

    Posted 11 years ago #
  6. elderberry
    Member

    Thanks @Danieliser, it works! I had to do it the long way, as I couldn'r quite get the syntax right in a single echo... :-)

    // add slider in the header
    function show_slider() {
    echo "<div id=\"slider\">";
    echo do_shortcode('[smoothslider id=1]');
    echo "</div>";
    }
    add_action('thematic_header','show_slider',0);

    Posted 11 years ago #
  7. Danieliser
    Member

    Should be something

    function'function show_slider() {
    echo '<div id="slider">' . do_shortcode('[smoothslider id=1]') . '</div>';
    }
    add_action('thematic_header','show_slider',0);
    Posted 10 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.