• Resolved sjoerd89

    (@sjoerd89)


    Hi all,

    not sure if this is the right place on the forum to ask this but let’s try.
    I have a function that shows a linkedin share button on my website. It looks like this:

    function wpb_linkedin_share_after($content) { 
    $sharecode .= '<script src="//platform.linkedin.com/in.js" type="text/javascript"> lang: en_US</script>
    <script type="IN/Share" data-counter="top"></script>'; 
    $newcontent = $content . $sharecode; 
    return $newcontent; 
    } 
    add_filter('the_content', 'wpb_linkedin_share_after');

    Now i would like this only to show up on “post” types. I read about the part where you have to specify what kind of type of page it is but can’t figure it out.

    Thanks for your help!

    Sjoerd

Viewing 6 replies - 1 through 6 (of 6 total)
  • maybe you should try doing a conditional statement.

    if(get_post_type() == 'post') {
    
    sharecode .= '<script src="//platform.linkedin.com/in.js" type="text/javascript"> lang: en_US</script>
    <script type="IN/Share" data-counter="top"></script>'; 
    $newcontent = $content . $sharecode; 
    return $newcontent;
    } else{
    return $content;
    }

    You would have to add the post types you want to check for. I’m not sure if it what you are looking for.

    Thread Starter sjoerd89

    (@sjoerd89)

    You would have to add the post types you want to check for. I’m not sure if it what you are looking for.

    I would like to have it on all post pages. But in your code i do not see where i have to specify this.

    your original code should put it on each post. I thought you wanted it only on specific post types. Are you wanting it on every post or only once per page. I’m a little confused when you say post page.

    Thread Starter sjoerd89

    (@sjoerd89)

    I am sorry if i am not completely clear with my question.
    In wordpress i have two places i make pages for my website:
    1: Pages
    2: Posts

    With my original code, the function showed on every page of my website. But i would like it to only show on the post type pages. Inside the posts, i have two categories if that is needed but i want the function to show on both categories.

    You just want it to post on the homepage where your blog post are being displayed.

    if(is_home() ){
    
    sharecode .= '<script src="//platform.linkedin.com/in.js" type="text/javascript"> lang: en_US</script>
    <script type="IN/Share" data-counter="top"></script>'; 
    $newcontent = $content . $sharecode; 
    return $newcontent;
    } else{
    return $content;
    }
    Thread Starter sjoerd89

    (@sjoerd89)

    Thanks for your time, i got it too work!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Function only show on posts’ is closed to new replies.