WP Short Code Help Please

12 replies
Hello wonderful programmers,

I am using a shopping cart with the Cart66 (lite version) and everything works great except for the return shopping button. This button is supposed to take the user back to the previous page but is taking them to a home page.

I would like to create a shortcode link and button that the customer will click on instead to take them back to where they once came from.

The site is using S2 member plugin, and some how I managed to muster up the code which takes members to their personal page - which they go to on login but also are linked to in the header.

Here is the section of that code in the header:

PHP Code:
<div id="navigation">
                <?php if (get_option(THEME_PREFIX "menu_management")) : ?>
                <?php wp_nav_menu(array('theme_location' => 'main_menu''container_class' => 'menu-header')); ?>
                <?php else : ?>
                <ul class="menu">
                    <li <?php if (is_home()) { echo 'class="current"'; } ?>><a href="<?php echo get_option('home'); ?>/" title="Reception">Reception</a></li>
                    
                    <li><a href="<?php echo S2MEMBER_LOGIN_WELCOME_PAGE_URL?>">VIP</a></a>
                    </li>
                    
                    <?php wp_list_pages('title_li='); ?>
                    
                    <?php if (get_option(THEME_PREFIX "twitter_link")) { ?>
                    <li class="twitter"><a href="http://twitter.com/<?php echo get_option(THEME_PREFIX "twitter_link"); ?>" title="Twitter.com">Twitter</a></li>
                    <?php ?>
                </ul>
                <?php endif; ?>
            </div> <!-- navigation -->
So, I am looking to take that "S2MEMBER_LOGIN_WELCOME_PAGE_URL" and make it a link and make it a link with button which can be displayed anywhere I embed it on the site.

I tried this code and added to my functions php file, but it did not work:

PHP Code:
function vippage() {
add_shortcode('vip', 'vippage');
      return <a href="<?php echo S2MEMBER_LOGIN_WELCOME_PAGE_URL?>">VIP</a>;
}
Am I even close to doing what I am looking to do?

Anyone know what I might be missing?

I spent 8 hours yesterday trying to figure out how to create this link, lol I have completely reverted back to noob status.
#code #short
  • Profile picture of the author Donald77
    In the header code there's one thing weird for sure:

    <a href="<?php echo S2MEMBER_LOGIN_WELCOME_PAGE_URL; ?>">VIP</a></a>

    has two </a>closing tags



    In your code instead the error is that the add_shortcode must be outside the function, after it:


    Code:
    function vippage() {
          return <a href="<?php echo S2MEMBER_LOGIN_WELCOME_PAGE_URL; ?>">VIP</a>;
    }
    add_shortcode('vip', 'vippage');
    Signature

    ____________________

    {{ DiscussionBoard.errors[3824079].message }}
    • Profile picture of the author Jill Carpenter
      ok, popped this in just before the ?> at the end:

      PHP Code:
      // Special Shorties
      function vippage() {
            return <a href="<?php echo S2MEMBER_LOGIN_WELCOME_PAGE_URL?>">VIP</a>;
      }
      add_shortcode('vip', 'vippage');
      and error still results on the line with the redirection link on it.

      Funny how it is working in the header.

      There has to be a way to make this into a link.

      The other thought is to make this into a php file of it's own or on an html type page so I can make it a clickable regular link but would think a shortcode would be more efficient?

      Any thoughts on the best way to do this are appreciated.
      Signature

      "May I have ten thousand marbles, please?"

      {{ DiscussionBoard.errors[3824155].message }}
  • Profile picture of the author Donald77
    Did you actually place the tag [vip] in the page ?

    Probably you already know, but add_shortcode replace a tag with the output of a function.
    In your case it's looking for [vip] in order to replace it with <?php echo S2MEMBER_LOGIN_WELCOME_PAGE_URL; ?>

    For tag i don't mean the post's tag, but just a text string within []
    Signature

    ____________________

    {{ DiscussionBoard.errors[3824212].message }}
    • Profile picture of the author Jill Carpenter
      When I drop the code into the file, and then go back to click on edit the page I get an error message - and it always falls on the line with that s2 code on it.

      When I remove that section, the backend goes back to working.
      Signature

      "May I have ten thousand marbles, please?"

      {{ DiscussionBoard.errors[3824235].message }}
      • Profile picture of the author Donald77
        Originally Posted by Jill Carpenter View Post

        When I drop the code into the file, and then go back to click on edit the page I get an error message - and it always falls on the line with that s2 code on it.

        When I remove that section, the backend goes back to working.
        If you simply add the function in the functions.php you get the error or not ? Or you get the error when you add the [vip] tag too ?

        Can you maybe paste here the error ?
        Signature

        ____________________

        {{ DiscussionBoard.errors[3824278].message }}
        • Profile picture of the author Jill Carpenter
          Originally Posted by Donald77 View Post


          Can you maybe paste here the error ?
          Here is my routine:

          Go to the bottome of the page:



          Insert code and save:



          Saving brings me to this option:



          Open the tab with wordpress, and select pages:



          And get this message:

          Signature

          "May I have ten thousand marbles, please?"

          {{ DiscussionBoard.errors[3824438].message }}
  • Profile picture of the author Donald77
    sorry i totally miss to correct another error

    the function should be :

    PHP Code:
    function vippage() {
          return 
    '<a href="'S2MEMBER_LOGIN_WELCOME_PAGE_URL'">VIP</a>';
    }
    add_shortcode('vip''vippage'); 
    Signature

    ____________________

    {{ DiscussionBoard.errors[3824439].message }}
    • Profile picture of the author Jill Carpenter
      Many thanks to you!

      Any idea what I need to add for the picture reference?

      I can call it a differerent shortcode as it will have reference to a button image.

      [vip button one]
      Signature

      "May I have ten thousand marbles, please?"

      {{ DiscussionBoard.errors[3824648].message }}
  • Profile picture of the author Donald77
    I'm not sure i've understood your question.

    Anyway i can't remember if the space is allowed in the shortcode's tag, so let's say you use [vip-button-one] instead of [vip button one].


    PHP Code:
    function vippagebutton() {
          return 
    '<a href="'S2MEMBER_LOGIN_WELCOME_PAGE_URL'"><img src="URL_OF_BUTTON_IMAGE" /></a>';
    }
    add_shortcode('vip-button-one''vippagebutton'); 
    You have to find URL_OF_BUTTON_IMAGE, or, if the image is named for example button.gif and it is located in the wp-content/themes/YOURTHEME folder, use this


    PHP Code:
    function vippagebutton() {
          return 
    '<a href="'S2MEMBER_LOGIN_WELCOME_PAGE_URL'"><img src="'.get_bloginfo('template_directory').'/button.gif" /></a>';
    }
    add_shortcode('vip-button-one''vippagebutton'); 
    Signature

    ____________________

    {{ DiscussionBoard.errors[3824802].message }}
    • Profile picture of the author Jill Carpenter
      Going based on the second model - will that template_directory work with an image that is located here:

      vip/wp-content/plugins/cart66-lite/images/continue-shopping.png

      ?

      or is there something called plugin_directory ?
      Signature

      "May I have ten thousand marbles, please?"

      {{ DiscussionBoard.errors[3824911].message }}
  • Profile picture of the author Donald77
    If you're using wordpress = or > 2.9 you have the constant named WP_PLUGIN_URL;

    this means you could use

    PHP Code:
    return '<a href="'S2MEMBER_LOGIN_WELCOME_PAGE_URL'"><img src="'.WP_PLUGIN_URL.'/cart66-lite/images/continue-shopping.png"'
    Hope that helps
    Signature

    ____________________

    {{ DiscussionBoard.errors[3825725].message }}
    • Profile picture of the author Jill Carpenter
      Ok, tried putting the image in my images file for the theme and using that option but not working, and tried the one just above going into the plugins directory and no luck there either.

      I am deathly ill, how was that for delayed response?

      Seem to be missing something still.

      PHP Code:
      // Special Shorties
      function vippage() {
            return 
      '<a href="'S2MEMBER_LOGIN_WELCOME_PAGE_URL'">VIP</a>';
      }
      add_shortcode('vip''vippage');

      // Button Shortie
      function vippagebutton() {
            return 
      '<a href="'S2MEMBER_LOGIN_WELCOME_PAGE_URL'"><img src="'.get_bloginfo('template_directory').'/continue-shopping.png" /></a>';
      }
      add_shortcode('vip-button-one''vippagebutton');  

      ?> 
      I'm able to put the [vippagebutton] on the post but it doesn't do anything.
      Signature

      "May I have ten thousand marbles, please?"

      {{ DiscussionBoard.errors[3836737].message }}

Trending Topics