There is many ways to do it, create a shortcode to place anywhere you want or filter the post content and add what you want.
If you plugin is not activate, this will not display,
<?php
/**
* Plugin Name: Europhonica Image/Vidéo switch (by Jules)
*/
// the_content method
add_filter( 'the_content', 'image_my_switch_function_content' );
function image_my_switch_function_content($content){
if(is_user_logged_in()){ // change with your conditions
$content="<p>Image</p>". $content
}
return $content;
}
// shortcode method
add_shortcode('show_image', 'image_my_switch_function_shortcode');
function image_my_switch_function_shortcode($atts, $content="null") {
if(is_user_logged_in()){ // change with your conditions
return '<p>Image</p>';
}
}
// Enable the use of shortcodes in text widgets.
add_filter( 'widget_text', 'do_shortcode' );
?>
The the_content
filter will be embed in any post, page… depending on your conditions.
With add_shortcode method the shortcode can be add manually (in the content or widget) or directly in the template with do_shortcode()
.
Directly in your template file :
echo do_shortcode('[show_image]');
You can read more about these functions add_shortcode(), do_shortcode(), the_content
Hope it helps!