Search code examples
phphtmlwordpressshortcode

Wordpress Shortcode not working with WP Codex command and PHP


Below is a php issue I am having, it works in other ways but doesn't work the way I wish too.

Basically I wish to add the WP login and logout commands to the the A-HREF links, but the closing short code doesn't seem to be taken effect and I would like to know why and hopefully fix this problem.

<?php
    echo do_shortcode('[not-level-visitors]') .
        '<div id="SignUp">
            <ul>
                <li><img src="http://dev.universitycompare.com/wp-content/themes/blue-and-grey/images/icons/user_icon.png" alt="User Icon My Account University Compare" />
                    <a href="http://dev.universitycompare.com/account/" style="margin: 0px 0px 0px -8px;">My Account</a>
                </li>
                <li>
                    <a href="' .  wp_logout_url($redirect) . '">Log Out</a>
                </li>
            </ul>
        </div>' . 
    do_shortcode('[/not-level-visitors]');
?>

Basically the above code is kind of working, but I just need the closing shortcode to work as it appears in my html and is not being recognised - I have created the above code from this below snippet that I am already using that works completely:

<?php
    echo do_shortcode('[level-visitors]
        <div id="SignUp">
            <ul>
               <li>
                   <a href="#">Sign Up</a>
               </li>
               <li>
                   <a href="#">Login</a>
               </li>
            </ul>
        </div>
    [/level-visitors]');
?>

Solution

  • The main difference I spotted is the single call vs multiple calls to do_shortcode, I assume it's failing to match the regex.

    Maybe this will work:

        echo do_shortcode('[not-level-visitors]
            <div id="SignUp">
                <ul>
                    <li><img src="http://dev.universitycompare.com/wp-content/themes/blue-and-grey/images/icons/user_icon.png" alt="User Icon My Account University Compare" />
                        <a href="http://dev.universitycompare.com/account/" style="margin: 0px 0px 0px -8px;">My Account</a>
                    </li>
                    <li>
                        <a href="' .  wp_logout_url($redirect) . '">Log Out</a>
                    </li>
                </ul>
            </div>[/not-level-visitors]');