• Hi there,

    I have put a function in my function.php file which creates the necessary html code to display a tab. First of all, here’s the function:

    function alexandria_tabs() {
    
    	if( have_rows('fin-de-page') ):
    
    // Vérifier si le champ contenu flexible dispose de données
    
        while( have_rows('fin-de-page') ) : the_row();
    
        // Ciblage du layout
            $layout = get_row_layout();
    
            // Avis Utilisateurs
    
            if( $layout === 'avis-utilisateurs' ): 
    
    	// Write here the names you want to assign to each tab
    	$alexandria_tab_1 = "Tab Name 1";
    	$alexandria_tab_2 = "Tab Name 2";
    	$alexandria_tab_3 = "Tab Name 3";
    	$alexandria_tab_4 = "Tab Name 4";
    	$alexandria_tab_5 = "Tab Name 5";
    
    	// Write here the content you want to want to assign to each tab
    	$alexandria_content_1 = '[tab icon="fa-th-large"] Alternatives[/tab]
    [tab icon="fa-heart"] Les avis de nos lecteurs[/tab]
    [tabcontent]Tab Content Here[/tabcontent]
    [tabcontent]content>[/tabcontent]
    [/wptabsy]';
    	$alexandria_content_2 = "Content 2";
    	$alexandria_content_3 = "Content 3";
    	$alexandria_content_4 = "Content 4";
    	$alexandria_content_5 = "Content 5";
    
    	// If you need to put plugin's shortcode in your content, just specify
    	// them here
    	$alexandria_shortcode_1 = "[my_shortcode";
    	$alexandria_shortcode_2 = "[my_shortcode";
    	$alexandria_shortcode_3 = "[my_shortcode";
    	$alexandria_shortcode_4 = "[my_shortcode";
    	$alexandria_shortcode_5 = "[my_shortcode";
    
    	// The above lines contains the HTML code which which will be generated
    	// to display the Tabs
    	echo'<div class="tab_container">
    		<input id="tab1" type="radio" name="tabs" checked>
    		<label for="tab1"><i class="fa fa-code"></i><span>'; echo $alexandria_tab_1; echo'</span></label>
    
    		<input id="tab2" type="radio" name="tabs">
    		<label for="tab2"><i class="fa fa-pencil-square-o"></i><span>'; echo $alexandria_tab_2; echo'</span></label>
    
    		<input id="tab3" type="radio" name="tabs">
    		<label for="tab3"><i class="fa fa-bar-chart-o"></i><span>'; echo $alexandria_tab_3; echo'</span></label>
    
    		<input id="tab4" type="radio" name="tabs">
    		<label for="tab4"><i class="fa fa-folder-open-o"></i><span>'; echo $alexandria_tab_4; echo'</span></label>
    
    		<input id="tab5" type="radio" name="tabs">
    		<label for="tab5"><i class="fa fa-envelope-o"></i><span>'; echo $alexandria_tab_5; echo'</span></label>
    
    		<section id="content1" class="tab-content">
    			<h3>Headline 1</h3>
    			<p>'; echo $alexandria_content_1;
    		echo '</section>
    
    		<section id="content2" class="tab-content">
    			<h3>Headline 2</h3>
    			<p>'; echo $alexandria_content_2;
    		echo '</section>
    
    		<section id="content3" class="tab-content">
    			<h3>Headline 3</h3>
    			<p>'; echo $alexandria_content_3;
    		echo '</section>
    
    		<section id="content4" class="tab-content">
    			<h3>Headline 4</h3>
    			<p>'; echo $alexandria_content_4;
    		echo '</section>
    
    		<section id="content5" class="tab-content">
    			<h3>Headline 5</h3>
    			<p>'; echo $alexandria_content_5;
    		echo '</section>
    	</div>';
    
            endif;
    
        endwhile;
    
    endif;
    
    }

    You can see that this is some basic stuffs. The defined variables are here to simplify the process of renaming the tabs, the headlines, and the content.

    The thing I want to know is how to make the content variable able to display shortcodes too, because the tab can be outside the loop. This probably possible, I have found some related articles speaking about add_filter, add_action… but because I’m beginning on PHP, I need some more information.

    I know i can put manually a do_shortcode, but the thing is I want the content variables to disp^lay both text and shortcode, like in the visual editor of wordpress. Is it possible?

  • The topic ‘Question about a variable containing a shortcode…’ is closed to new replies.