Alexander
Alexander

Reputation: 111

Why my function do not working twice?

I have simple function for displaying social buttons:

<?php function wc_social_buttons() {
    global $post;
?>
    <div class="social-buttons">
        <div id="facebook" data-url="<?php echo get_permalink(); ?>" data-text="<?php the_title(); ?>" data-title=""></div>
        <div id="twitter" data-url="<?php echo get_permalink(); ?>" data-text="<?php the_title(); ?>" data-title=""></div>
        <div id="google-plus" data-url="<?php echo get_permalink(); ?>" data-text="<?php the_title(); ?>" data-title=""></div>
        <div id="pinterest" data-url="<?php echo get_permalink(); ?>" data-text="<?php the_title(); ?>" data-title=""></div>
        <div id="stumbleupon" data-url="<?php echo get_permalink(); ?>" data-text="<?php the_title(); ?>" data-title=""></div>
        <div id="digg" data-url="<?php echo get_permalink(); ?>" data-text="<?php the_title(); ?>" data-title=""></div>
    </div>
    <div class="clear"></div>
<?php
}?>

Then i am using it in header of the page (for sticky menu) and in pages content. But it is displaying only in the header. All HTML this function returns drawing in page content, but displaying only in header. Any options display:none do not used. If i ramove function from header - all its HTML normally displaying in pages content. May someone explain me what is this?...

Upvotes: 1

Views: 146

Answers (2)

Madurai
Madurai

Reputation: 297

Check with this

Header

<div id="1"> Id Must be unique in Page </div>

Page Content

<div id="1"> Id must be unique don't use same id in a page </div>

In your code change Change Id as Class .

<div class="facebook" data-url="<?php echo get_permalink(); ?>" data-text="<?php the_title(); ?>" data-title=""></div>

Now You can use two or more times by calling the function in a page.

Upvotes: 2

Mostafa Talebi
Mostafa Talebi

Reputation: 9183

your problem is that you are declaring it probably twice. for the second use in the body section only put this code:

<?php
wc_social_buttons()
?>

Upvotes: 1

Related Questions