How to create a shortcode
-
I read the API tutorial for creating wordrpess shortcodes and I’m still not quite sure what to do.
I’m basically trying to create a dynamic login link into a shortcode
I’m trying to put this into shortcode form
<?php if ( is_user_logged_in() ) { ?> <div class="logoutformat">< a href="<?php echo wp_logout_url( get_permalink(716) ); ?>" title="Logout">Logout</a> </div> <?php } else { ?> <div class="loginformat"> <a href="<?php echo wp_login_url(); ?>" title="Login">Login</a></div> <?php } ?>
According to how I understand the codex, shouldn’t the function I input into my functions.php file look something like this?
function foobar_func( $atts ){ return "if ( is_user_logged_in() ) { ?> <div class='logoutformat'>< a href='<?php echo wp_logout_url( get_permalink(716) ); ?>' title='Logout'>Logout</a> </div> <?php } else { ?> <div class='loginformat'> <a href='<?php echo wp_login_url(); ?>' title='Login'>Login</a></div> <?php } "; } add_shortcode( 'foobar', 'foobar_func' );
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘How to create a shortcode’ is closed to new replies.