I have to insert some sliders in some particular pages of wordpress site.


when I have added the slider code, its appearing all at a time.

How can if do something like:

if (page is wedding){
echo wedding slider
if (page is portrait){
echo portrait slider

the page admin side url is:


I tried something like below:

<div class="layout-full">
            <header class="entry-header">
                <h1 class="entry-title"><?php single_cat_title(); ?></h1>

            <!-- wedding --THIS DOSN'T WORK :( -->      
                $title = single_cat_title();
                if ( $title == "Wedding")  {
                    echo do_shortcode('[metaslider id="1710"]');

            <!--portrait -->
            <?php echo do_shortcode('[metaslider id="1718"]'); ?> 

            <!--travel -->
            <?php echo do_shortcode('[metaslider id="1714"]'); ?>


but the if condition doesn't work, Instead 'wedding' is printed on the page.


As I understand you want to display your slide in specific pages, so you need to control it using if condition.

debug the code before use,

  1. Only on front page / home page

    is_front_page(); // Use this function

    More reading . https://developer.wordpress.org/reference/functions/is_home/ https://developer.wordpress.org/reference/functions/is_front_page/

  2. Get Current page name $pagename = get_query_var('pagename');

More details , stack overflow answer .https://stackoverflow.com/questions/4837006/how-to-get-the-current-page-name-in-wordpress

  1. Using Advance custom fields , ACF is a free plugin but I think repeater field is paid. anyway it have nice control customfilds.

    Follow this resources https://www.advancedcustomfields.com/ https://www.advancedcustomfields.com/resources/repeater/

     $post_type = get_post_type();
      //echo wedding slider
    else if($post_type=='portrait'){
     //echo portrait slider
  • thanks for the answer, but I am not sure if 'wedding' and 'portrait' are actually post types-- – Sourabh May 12 '18 at 5:57
  • if you are trying to add the slider in pages use page id or check with is_page() with page slug or id – Shameem Ali May 12 '18 at 6:27
  • Please edit your answer, and add an explanation: why could that solve the problem? – fuxia May 12 '18 at 6:34
  • you can use following condition to check current page with page id so if condition satisfy echo slider ` if (is_page('346') ): //echo endif;` – Shameem Ali May 12 '18 at 6:41
  • @ShameemAliP.K I tried that, but its not a page. is_tax('department') is true, but I am having hardtime filtering out more. – Sourabh May 12 '18 at 6:49

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.