WordPress.org

Ready to get started?Download WordPress

Forums

Content Not Displaying Shortcodes (3 posts)

  1. BTDmedia
    Member
    Posted 1 year ago #

    Hello,
    I am having trouble displaying shortcodes correctly on my main post content. (Example - You can see all the [soundcloud id='']. I know it's not a problem with the plugin because no shortcodes work.)

    Instead of using:

    <?php the_content(); ?>

    I am currently using:

    <?php echo preg_replace("/\< *[img][^\>]*[.]*\>/i","",get_the_content(),1); ?>

    which hides the first image from each post because my featured image is automatically displayed on top. However, even when I replaced what I'm currently using back with the normal 'php the_content' code it is still not displaying my shortcodes correctly. Is there a way to filter the first image out and include shortcodes via function.php OR some other workaround? I feel like it's something easy I'm overlooking causing this error.

    Thanks in advance!

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    you could try:

    <?php echo apply_filters('the_content', preg_replace("/\< *[img][^\>]*[.]*\>/i","",get_the_content(),1) ); ?>

    or:

    <?php echo preg_replace("/\< *[img][^\>]*[.]*\>/i","",apply_filters('the_content',get_the_content()),1); ?>

    or:

    <?php echo preg_replace("/\< *[img][^\>]*[.]*\>/i","",do_shortcode(get_the_content()),1); ?>

    http://codex.wordpress.org/Function_Reference/apply_filters
    http://codex.wordpress.org/Function_Reference/do_shortcode

  3. BTDmedia
    Member
    Posted 1 year ago #

    Everyone of them seemed to do the trick.

    Wow, I couldn't thank you enough! I appreciate it!

Topic Closed

This topic has been closed to new replies.

About this Topic