Theme - OceanWP Page Builder - Elementor
Single Post templated created using Elementor
I am trying to add custom code for the SINGLE BLOG POST.
Using a conditional tag "is_single", I want to display social sharing buttons for my blogs/posts
Now, I researched and found out WP conditional tags can't be used in functions.php directly since it has to check THE LOOP before it runs the condition check.
Does anybody have an idea of how can I use a conditional tag in functions.php using some hook provided by OCEAP WP.
I don't want to use a plugin for social share since it bloats.
function sshare()
{
if(is_single())
{
$postUrl = 'http' . ( isset( $_SERVER['HTTPS'] ) ? 's' : '' ) . '://' . "{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"; ?>
<section class="sharing-box content-margin content-background clearfix">
<h5 class="sharing-box-name">Don't be selfish. Share the knowledge!</h5>
<div class="share-button-wrapper">
<a target="_blank" class="share-button share-twitter" href="=<?php echo $postUrl; ?>&text=<?php echo the_title(); ?>&via=<?php the_author_meta( 'twitter' ); ?>" title="Tweet this">Tweet this</a>
<a target="_blank" class="share-button share-facebook" href=".php?u=<?php echo $postUrl; ?>" title="Share on Facebook">Share on Facebook</a>
<a target="_blank" class="share-button share-googleplus" href="=<?php echo $postUrl; ?>" title="Share on Google+">Share on Google+</a>
</div>
</section>
<?php
}
}
add_action('ocean_before_single_post_content', 'sshare',10);
?>
Now I am not sure which hook to use or am I using the whole syntax wrong?
Is it not working because I created a custom Single Post Template using Elementor? So it overrides any custom function run on the single post template?