Support » Plugins » Plugin the_content problem

  • Hi,

    I whant to create my first plugin and i started from a basic plugin to add it after the post content using add_action the_content and it work. but if i add a require_once or include in my plugin. the included appear on top of the content and not under. did some people fixed same issue with included content apearing like me on the top of the post content?

    All other code are at the right place but not the included content. I tested that if you open and close php code in your plugin it do the same thing. Why this happen?

    Some this like that

    function socialstars_display($content)
    	// this is where we'll display the Stars Social
    	$options['page'] = get_option('socialstars_on_page');
    	$options['post'] = get_option('socialstars_on_post');
    	if ( (is_single() && $options['post']) || (is_page() && $options['page']) || (is_page(3777) && $options['post']) )
    		$searchform = require_once(dirname(__FILE__).'/includes/test.php');
    		//$searchform = include 'includes/searchform2.php';
    		//$starsinfos = require_once(dirname(__FILE__).'/includes/stars-infos.php');
    		$socialstars_box = '<h2>Photoset '.get_the_title().'</h2>[flickr-gallery mode="search" tags="'.get_the_title().'"]'.
    // RSS NEWS
    '<h2>News '.get_the_title().'</h2>';
    $artistencode = urlencode(get_the_title());  
    include_once(ABSPATH.WPINC.'/rss.php'); // path to include script
    $feed = fetch_rss(''.$artistencode.'&ei=UTF-8&fl=0&x=wrt'); // specify feed url
    $items = array_slice($feed->items, 0, 7); // specify first and last item
    if (!empty($items)) :
    foreach ($items as $item) : 
    echo '<h3><a href="'.$item['link'].'"  target="_blank">'.$item['title'].'</a></h3>'.$item['description'].'';
    		return $content . $socialstars_box;
    	} else {
    		return $content;
    add_action('the_content', 'socialstars_display');

    Even a very simple include doesn’t work like,

    $socialstars_box = require_once(dirname(__FILE__).'/includes/test.php');

    The included file will appear over the post content in a post page.

  • The topic ‘Plugin the_content problem’ is closed to new replies.