Shortcodes not working in custom theme
-
Hi all,
I’m building a theme and have added some shortcodes using add_shortcode as per the WordPress codex. When I try to use them, the theme just renders the shortcode markup and doesn’t return what the shortcode is supposed to return.
I disabled all plugins but that didn’t work. I then setup a brand new installation of WordPress 3.7.1 that has no plugins and no customization at all. I then added my shortcode function to functions.php and tested it – still no go. It just displays the shortcode markup.
Here is the functions.php code:
function permalink_test( $atts ) { extract( shortcode_atts( array( 'id' => 1, 'text' => "" ), $atts ) ); if( $text ) { $url = get_permalink( $id ); return( "<a href='$url'>$text</a>" ); } else { return( get_permalink( $id ) ); } } add_shortcode( 'permalink', 'permalink_test' );
I got that code from the Digging Into WordPress book so it should be ok.
Here is index.php from the basic test theme:
<?php while( have_posts() ) : the_post(); the_title(); ?> [permalink id=1, text="hello"] <? endwhile; ?>
I’m pretty sure that’s ok but am more than happy to be told it is wrong, e.g. if I’m using something outside the loop when it should be inside, etc.
What could be causing the shortcodes to not work?
Thanks
- The topic ‘Shortcodes not working in custom theme’ is closed to new replies.