• Hi
    I’m trying to put the following code in a text widget
    <?php if ( is_user_logged_in() ) { ?><a href="index.php?p=74">Profile</a> <?php } ?>
    Which should show a link to the profile page only if the user is logged in. However this shows regardless of whether the are logged in or not.
    Have I made an error in the command?

Viewing 1 replies (of 1 total)
  • Hi teejayuu.

    The WP text widgets won’t execute php code. You could use a plugin ( like PHP Code Widget ) or the widget_text filter

    function php( $wtext ) {
    	if( false !== strpos( $wtext, "<?php" ) ) {
    		ob_start();
    		eval( "?>" . $wtext );
    		$wtext=ob_get_contents();
    		ob_end_clean();
    	}
    	return $wtext;
    }
    add_filter('widget_text','php');

    ( please, use the function only if you are sure no role can access the widgets but the admins, otherwise a plugin is safer! )

Viewing 1 replies (of 1 total)
  • The topic ‘Text Widget issues’ is closed to new replies.