It's a weird problem that looks like to have something todo with the WP SEO plugin from Yoast. If I disable it ( and no other plugins are running ), the output is what I expect it to be.

It shows the content of the page that I added in the post editor, together with the content of the included file.

But if the WP SEO plugin is active, then it still shows the content from the post editor followed by 1. The content from the included file isn't there.

I made a very basic demo with code from the codex that on my machine ( in both wp 3.9 and wp 4.0 ) show a 1 instead of the content from the included file. But only is WP SEO from Yoast is active. The code is pretty basic as you can see here http://www.codeshare.io/16KHK

Does anyone have an idea why this would break it?

$template_content = require_once( plugin_dir_path( __FILE__ ) . 'cpt-template.php' );

While this works fine.

$template_content = 'template test';

If I echo the $template_content after including it, the content is there. So it does find it and loads the content. But somehow when WP SEO is active, instead of returning the data that is clearly there ( echoing shows it ), it just shows 1?

I tried it with different default wp themes as well, and it all results in the same thing.

Any ideas what this could be? If someone could maybe try the this code http://www.codeshare.io/16KHK as well and verify it's not just my machine where it breaks if the WP SEO plugin is active?

  • Add any relevant code directly to the question, do not rely on external links. Thanks. – Milo Nov 28 '14 at 12:59
  • Why don't you just make a function inside the cpt-template.php and then call it ? require_once( plugin_dir_path( FILE ) . 'cpt-template.php' ); $template_content = cptTemplateGetOutput(); and inside cpt-template.php you can have the function that returns the output. – Laxmana Nov 28 '14 at 13:19
  • what does cpt-template.php contain? if it doesn't return anything, then require_once returns 1, meaning the include succeeded. if you want to include a file that outputs content directly, you have to use an output buffer. – Milo Nov 29 '14 at 0:10

WP SEO execute the add_filter( 'the_content', 'cpt_template' ); multiple times and override the content.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.