sm21guy
sm21guy

Reputation: 626

add html and script into wordpress

I am new to plugin development in wordpress.

I want to add just a simple html code to wp_footer using action hook I just learned from wordpress codex.

<?php
        /* 
        Plugin Name: test
        Plugin URI: http://mysite.com
        Description: test
        Version: 1.0 
        Author: me
        Author URI: http://mysite.com
        */  

    function addbar(){
    echo '<div id="cbar">';
    echo '</div>';
    }

    if ( is_user_logged_in() ){
       add_action('wp_footer','addbar');
    } else {
    }
?>

This code does not works , it crashes my site.

Upvotes: 0

Views: 126

Answers (1)

user2193789
user2193789

Reputation:

i think as this function is in pluggable.php, that the function doesn't exist when the plugin is activated. This should mean that you just have to delay the loading of your logic.

function addbar(){
if(is_user_logged_in()){
    echo '<div id="cbar">';
    echo '</div>';
}
}

 add_action('wp_footer','addbar');

Upvotes: 1

Related Questions