Support » Themes and Templates » Shortcodes not working (custom theme)

  • Resolved giammo

    (@giammo)


    I’m new to the WordPress, and although I’m not a beginner in coding, I have some troubles.

    I think the issue is in the custom theme (that was created by me), because when I switch over to default theme, all things work fine.

    All shortcodes seem to not be working. eg. I tried installing the YouTube Embed plugin to display a YouTube video, but the shortcode for that doesn’t render. But, also built in WP shortcodes don’t work either. For example, when I insert an image into a post or page, the image is ok but the caption don’t work correctly.

Viewing 3 replies - 1 through 3 (of 3 total)
  • if this, for example, happens in the single post, have a look into single.php of your theme … or post the code of that file here, so somebody can double check the code.

    generally, unless you have some code that supresses it, shortcodes would get rendered where you use the_content() in your theme’s files.

    Thread Starter giammo

    (@giammo)

    Firstly, thanks for the answer.
    This problem happens exactly into single.php.

    The code is this:

    <?php
    if ( have_posts() ) : while ( have_posts() ) : the_post();
    	echo '<h2 class="post-title page-header text-capitalize">'.get_the_title().'</h2>';
    	echo'<p class="meta">';
    		echo '<span class="author"><a href="'.get_author_posts_url(get_the_author_id()).'">'.get_the_author().'</a></span>';
    		echo ' | <span class="date">'.get_the_date('d-m-Y').'</span>';
    		echo ' | <span class="categories">'.get_the_category_list(' - ').'</span>';
    	echo '</p>';
    	$src = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full', false );
    	if(!empty($src)) {
    		echo '<img class="thumb thumbnail img-responsive" src="'.$src[0].'" alt="immagine '.esc_attr($title).'">';
    	}
    	echo '<p class="desc">'.get_the_content().'</p>';
    		
    	echo '</div>';
    	
    	endwhile;
    else:
    	echo "Post not found.";
    endif;
    ?>

    Certainly I made a mistake in the code (as I said I am a beginner).

    Thread Starter giammo

    (@giammo)

    The error was just the use of the_content() function, using get_the_content() function does not expand shortcodes.

    Now work perfectly.

    Thanks very much for making me reflect on the error. 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Shortcodes not working (custom theme)’ is closed to new replies.