Integrating wordpress into Drupal 7 site

So I had one plugin for Wordpress which I really wanted to use on one of my Drupal website. Naive approach was:

define('WP_USE_THEMES', false);
include_once './wp/wp-blog-header.php';

Only to get:

Fatal error: Cannot redeclare timer_start() (previously declared in /home/ariel/wwwroot/drupal-mine/includes/ in /home/site/wwwroot/site/includes/ on line 122

Turned out both Drupal and Wordpress define several function using same name (and neither uses namespaces, unfortunately.) After looking for other potential solutions, I decided to try to simply rename all offending functions inside Wordpress. Turned out it was just 4 of them:

find ./ -type f -exec sed -i 's/timer_start/wp_timer_start/g' {} \;
find ./ -type f -exec sed -i 's/timer_stop/wp_timer_stop/g' {} \;
find ./ -type f -exec sed -i 's/comment_form/wp_comment_form/g' {} \;
find ./ -type f -exec sed -i 's/image_resize/wp_image_resize/g' {} \;

After that I was able to get through "redeclare" error.

Next task was to clean up "unnecessaries" (extra meta/title tags, emoji-related code, etc. Below is final code I came up with. It is header and footer pieces, and your wordpress-code should go in the middle:

define('WP_USE_THEMES', false);
define('STYLESHEETPATH', '');
define('TEMPLATEPATH', '');
include_once './wp/wp-load.php';
global $wp_filter;
function disable_wp_emojicons() {
  // all actions related to emojis
  remove_action( 'admin_print_styles', 'print_emoji_styles' );
  remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
  remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
  remove_action( 'wp_print_styles', 'print_emoji_styles' );
  remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
  remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
  remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
  // filter to remove TinyMCE emojis
  add_filter( 'tiny_mce_plugins', 'disable_emojicons_tinymce' );
remove_action('wp_head', 'dns-prefetch' );
remove_action('wp_head', 'wp_resource_hints', 2 );
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'wp_shortlink_wp_head');
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'rest_output_link_wp_head');
remove_action('wp_head', 'wp_oembed_add_discovery_links');
remove_action('template_redirect', 'rest_output_link_header', 11, 0 );
$wpcode = ob_get_contents();
echo preg_replace('/^.+jquery\/jquery.+$/m', '', $wpcode);

This will ensure that all necessary css/js from wordpress plugin is loaded.

Unfortunately, since i replaced code inside wordpress code base, after each wordpress update, i have to re-run functions renaming code again.. I probably simply disable updates for time being, since that wordpress site is not exposed any way except via invoking plugin code.



Eres un genio.

Good post. I'm experiencing some of these issues as well..

Have a look at my page - sv388 Link Alternatif (<a href="

I like the helpful information you provide in your
articles. I will bookmark your weblog and check once more here frequently.
I'm moderately certain I will be informed many new stuff right right here!
Good luck for the next!

My webpage; <a href="

Asking questions are really pleasant thing if you are not understanding
something fully, however this piece of writing presents good understanding

Here is my webpage; <a href="">joker 123</a>

Howdy! Someone in my Myspace group shared this
website with us so I came to look it over. I'm definitely
loving the information. I'm bookmarking and will be tweeting this to my followers!
Wonderful blog and terrific design.

Look into my webpage: <a href=" Joker123 Gaming</a>

It's great that you are getting thoughts from this piece of writing as
well as from our dialogue made at this time.

Feel free to surf to my web-site ... <a href="

Link exchange is nothing else however it is just placing the other person's weblog link on your page at proper
place and other person will also do same for you.

Take a look at my webpage <a href="

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
1 + 12 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.