Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I fix a wordpress custom theme to work with plugins?

This is my first attempt at coding a custom wordpress theme and I'm almost there. There are a few bugs as there are with anything, but I've tried a few different options at fixing them but with no success.

The link is www.studiosimplicit.com/wp.

My first issue is with nivo slider on the events page (Www.studiosimplicit.com/wp/events). Initially I was having an issue with the plugin itself, where the images were being stacked on top of each other. To correct this I manually put in code to call in the nivo .js files, and that seemed to fix that issue. But now the loading image is there but the images don't load.

I've checked the URL of the images and that's not the issue. I also enabled the "post-thumbnails" feature (as suggested on the nivoslider website as a common fix to my issue) but that doesn't appear to have fixed it. It's worth nothing that when I switch to a default theme, the slider works fine. It's when I activate my custom theme that it breaks.

My second issue is with a plugin that is supposed to set a full screen background image, automatically resized to fit browser width. Again, the plugin works when I switch to a default theme but it breaks when I switch to my custom theme.

Please help!

like image 908
giwook Avatar asked Mar 11 '12 17:03

giwook


People also ask

Why are my WordPress plugins not working?

Log into the WordPress admin area, and activate each plugin one by one. Check your site after each activation. If it breaks, the last plugin you activated is causing the issue. If deactivating all of your plugins did not fix your site, you likely have a corrupted theme or WordPress core file.

Why is my customize not working on WordPress?

A plugin conflict can cause Customizer preview to stop loading or part of it to stop working properly. If you have a cache plugin or server cache. You need to purge it's cache contents and disable it. Clear your browser history and visit your Appearance -> Customize to see if it works.

How do I resolve a plugin issue in WordPress?

Go to Plugins → Installed Plugins and deactivate the plugin(s) you determined to be the source of the issue. You can leave the plugin deactivated and contact the plugin's developer to fix the problem.


2 Answers

By the sounds of it, your custom theme is missing the common hooks that allow plugins to alter/output their code.

To take a simple example, every theme should have a call to wp_head() somewhere in the <head> section of the output page. This allows a plugin to "hook" into your <head>, and for example, output code to load its Javascript.

Here's a real-life example. The WordPress Twentyeleven theme has this in its header.php file (traditionally the part of a theme that outputs the <head> section of any page):

... other <head> stuff
    wp_head();
?>  
</head>

The WP Nivo Slider uses this code when it calls wp_enqueue_script, for example, in its wp-nivo-slider.php file. Behind the scenes, wp_enqueue_script uses the wp_head() hook in the Twentyeleven theme to output the requested Javascript include in the <head> section (via a slightly circuitous route that ends up in wp_print_head_scripts by default.)

So, basically, if a plugin works with a provided theme, but doesn't work with your custom theme, your task is to find the hooks that are missing from your theme that the plugin is trying to use.

If you check the WordPress Theme Development documentation you'll find a list of hooks that themes should include under the section "Plugin API hooks". These are, specifically:

  • wp_head
  • wp_footer
  • wp_meta
  • comment_form

The important ones for most plugins will be wp_head and wp_footer. This is where most Javascript gets included, either in the head or the footer section (just before the closing <body> tag.)

Most plugins like Javascript sliders, image galleries, etc., will simply add a new script or two in the <head> or footer section of the website, and perhaps include CSS files to style their content, again in the <head> section, so those two are generally the only hooks they need.

So, my initial advice would be to make sure your custom theme includes a call to wp_head() at the end of its <head> section (copy the code from that working theme you've got) and also a call to wp_footer(), just before the closing </body> tag. The chances are good that that'll get most Javascript-based plugins working.

like image 115
Matt Gibson Avatar answered Sep 23 '22 21:09

Matt Gibson


Just for the record: I had a similar problem and I had to replace the line

<?php echo get_the_content() ?>

with this one:

<?php echo the_content() ?>

But I also had to include wp_head and wp_foot as explained by Matt.

like image 39
Peter Clause Avatar answered Sep 20 '22 21:09

Peter Clause