1

ENV: WordPress version 5.1 / MAMP Pro php v. 7.2.14

I'm building a new, custom theme for a site that has an old, custom theme. The new site is just a single theme, while the old site has a parent theme and a chid theme.

When I change the active theme to my new one, the shortcode that lives in the content area of a Page only renders the text of the shortcode.

When I activate the old child theme it renders perfectly.

Is there something I'm not doing in my new custom theme that is not enabling these shortcodes?

When I enable debugging, I can't get past the if() statement to get to line 196 of shortcodes.php

if ( empty( $tagnames ) ) {
    return $content;
}

// line 196 --v
$content = do_shortcodes_in_html_tags( $content, $ignore_html, $tagnames ); 

It's like my shortcode isn't gettting registered properly.

shortcode code in functions.php

function first_shortcode() {
    $content = '<h1>This is my first shortcode</h1>';
    return $content;
}
add_shortcode('my_shortcode', 'first_shortcode');

UPDATE

Adding template code snippets:

page.php

/**
 *Template Name: Page
 *
 */

global $pageType;
$pageType = "tier"; // this is used as a body tag class

get_header();

get_template_part( 'template-parts/navigation');

?>
<main id="main" class="main-container">
    <?php
        while ( have_posts() ) :
            the_post();

            get_template_part( 'template-parts/content', 'page' );

        endwhile; // End of the loop.
    ?>
</main>

<?php

get_footer();

content-page.php

<?php
/**
 * Template part for displaying page content in page.php
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package hdms
 */
?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

    <div class="container fat-margin">
        <div class="entry-content">
            <?php
            the_content();
            ?>
            <?php echo do_shortcode("[my_shortcode]"); ?>
            <p><strong>the above lives in php calling:</strong></p>
            <pre>
                &lt;?php echo do_shortcode("[my_shortcode]"); ?&gt;
            </pre>

        </div><!-- .entry-content -->
    </div><!-- .container -->
</article><!-- #post-<?php the_ID(); ?> -->


Admin (editing) Page Content:

enter image description here


Rendered using my new theme

enter image description here


Rendered using old theme:

enter image description here

  • Could you look at my answer below? Could you explain to me what you're trying to do/achieve? Also, explain to me the variable $tagnames – Remzi Cavdar May 29 '19 at 20:28
  • what is the code of page.php in your custom theme? – Michael May 30 '19 at 0:57
  • I made two WP themes and numerous child themes. And a couple of WP plugins. You say that you can't get past the if() statement, that means your doing something wrong there. Explain to us what you're trying to do and show us all your code or the relevant part. This: $tagnames – Remzi Cavdar May 30 '19 at 5:17
  • page.php & an include are here: gist.github.com/sroberson/30cefbf59b1b10b5667d2bca293dcff6 – Scott Jun 3 '19 at 18:15
0

I would recommend using single quotes if you want to include some HTML, also you need to return something otherwise nothing happens.

// WP Shortcode
function text_shortcode() {
    return '<strong>bold text:</strong> <a href="https://wordpress.stackexchange.com/questions/318934/shortcode-returns-escaped-html-tags">See wordpress.stackexchange.com</a>';
}
add_shortcode('bold-text', 'text_shortcode');

Your WordPress shortcode would be:

[bold-text]

See my other answers with examples:
- Shortcode created to check language not works
- Shortcode returns escaped HTML tags

  • The addShortcode() function in my functions.php fie does have single quotes. – Scott May 29 '19 at 20:26
  • @Scott It doesn't matter, you could use both single and double quotes! – Remzi Cavdar Sep 28 '19 at 13:43

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.