I am working in codeigniter and I want to fetch blog post on the my web
Site Homepage When I include two file
require_once('blog/wp-blog-header.php');
require_once('blog/wp-includes/link-template.php');
I got an error.
Fatal error: Cannot redeclare site_url() (previously declared in /home/homebidpro/public_html/dev/system/helpers/url_helper.php:83) in /home/homebidpro/public_html/dev/blog/wp-includes/link-template.php on line 3004
I Commented this function according to location file:
function site_url( $path = '', $scheme = null ) {
return get_site_url( null, $path, $scheme );
}
this error is removed and all functionality of website wotks But When I open
blog is not opening it is giving error
dev.homebidpro.com page isnât working
Blog and project location is same both are in dev Folder.
I stuck till now. Please give the solution as soon as possiable.
The rest of code is
public function blogData()
{
require_once('blog/wp-blog-header.php');
require_once('blog/wp-includes/link-template.php');
if($catagory !='')
{
$args = array( 'posts_per_page' => 3, 'category_name' => $catagory );
}
else
{
$args = array('posts_per_page' => 4);
}
$mypostsMov = get_posts( $args );
// echo "<pre>"; print_r($mypostsMov); die;
$mypostsarrayMov = array();
$i=0;
foreach ($mypostsMov as $post ) :
$excerpt = preg_replace("/<img[^>]+>/i", "", $post->post_content);
$mypostsarrayMov[$i]['post_title'] = strip_tags($post->post_title);
$mypostsarrayMov[$i]['content'] = strip_tags($post->post_content);
$mypostsarrayMov[$i]['permalink'] = get_permalink($post->ID);
$mypostsarrayMov[$i]['thumbnail'] =get_the_post_thumbnail($post->ID,array( 300, 200));
$i++;
endforeach;
wp_reset_postdata();
//echo "<pre>"; print_r($mypostsarrayMov); die;
//return $this->render('MovePlusServiceBundle:Default:recentpostCombined.html.twig',array('mypostsMov'=>$mypostsarrayMov, ));
return $mypostsarrayMov;
}
And site_url
function which is in codeigniter
if ( ! function_exists('site_url'))
{
function site_url($uri = '')
{
$CI =& get_instance();
return $CI->config->site_url($uri);
}
}
and siteurl function which is blog folder I already send you.
The issue you have is that CodeIgniter has a
site_url()
function in the url helper, and WordPress also has a functionsite_url()
which is defined within the wp-includes/link-template.php file.Because you’ve included link-template.php in your CodeIniter page, PHP is telling you you’re trying to create a function which already exists, which you can’t do.
From what I can think of, you need to either:
You might choose to implement a combination of these
A new established workaround found to fix this issue with WP6+ and CI4.3
change the link-template.php in wp-includes with the following addition:
This results in the admin and WordPress environment not being influenced by the presence of CodeIgniter, yet it leaves all functionalities operational. Tested successfully. Hope its useful to someone trying to combine these two.