Skip Navigation

[Resolved] Archive Layout Short Code Displaying Wrong Place

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 7 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

This topic contains 1 reply, has 1 voice.

Last updated by Arthur 7 years, 4 months ago.

Author
Posts
#543586

I have a simple shortcode with simple output, which I am trying to display on an Archive Layout.

1. Theme is stock Toolset Starter - with the Real Estate Reference Site applied.

2. This shortcode is registered properly with Toolset.

3. I am using the Visual Editor cell to call the shortcode.

4. The shortcode works JUST FINE and outputs the correct information.

5. I have tried disabling all plugins except the Toolset specific ones required for output, with no help to the problem.

THE PROBLEM:

No matter how I apply it, the shortcode output is displaying at the TOP OF THE PAGE, above the Header. In Source, it is displaying directly below the Body tag.

No matter what I do, or how I wrap it, that's where it ends up.

You can see the shortcode below - it is applied only to Taxonomy Archives. It simply retrieves all terms assigned to the current Taxonomy, and lists them as links. Inside the Layout cell, I am simply placing the shortcode:

[tax_list]

The output is very simple. <UL> / <LI> - nothing else.

If I place any other text or content within the same cell, above or below the shortcode, that content displays in the correct location just fine. But the shortcode output still ends up at the top of the page.

Why might this be happening and how to resolve it? Tx

function tax_terms_output( $atts ) {
		$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); 
		$taxonomy_slug = $term->taxonomy;
			$terms = get_terms( $taxonomy_slug, array( 'hide_empty' => false ));
				if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
				echo '<ul>';
				foreach ( $terms as $term ) {
				echo '<li><a href="/'. $term->taxonomy .'/'. $term->slug .'/">' . $term->name . '</a></li>';
				}
                 echo '</ul>';
           }
}

add_shortcode('tax_list', 'tax_terms_output');
#543608

Hello,

This is self-resolved, and was silly error as I realized that the output must be returned to the_content - not directly via echo in this case. LOL I do too much outside of wordpress sometimes, and not enough in it - so here was the problem.

To elaborate for anyone new to this, it means instead of using direct 'echo' as is shown in the example above, to rather assign all outputs to a variable, and then return that variable. This will then apply it properly within the_content.

The forum ‘Types Community Support’ is closed to new topics and replies.