Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
fixed formatting
Source Link
cjbj
  • 15k
  • 16
  • 42
  • 89

I'm trying to create a single template for the custom post type posts called 'press release' from a plugin.

This is the code I added to my plugin:

function single_press_release_template($single_template) {
     global $post;
     $plugin_path = plugin_dir_path( __FILE__ );
     if ($post->post_type == 'press_release') {
        if(file_exists($plugin_path . 'views/single-press_release.php')) {
            $single_template = $plugin_path . 'views/single-press_release.php';
            echo 'EXISTS! ' . $plugin_path . 'views/single-press_release.php';
        }
     }
     return $single_template;
}
add_filter( 'single_template', 'single_press_release_template');

The file single-press_release.php (located in the 'views' plugins directory) contains this code:

/**
 * Single Press Release
 *
 * @package WordPress
 */

<?php

echo 'Hello World';

?>

The result I get is a page without any main content (there is no 'hello world' text at all) but I can see the echo 'EXISTS! ' . $plugin_path . 'views/single-press_release.php':

blank main content

What am I doing wrong?

Thanks a lot!

I'm trying to create a single template for the custom post type posts called 'press release' from a plugin.

This is the code I added to my plugin:

function single_press_release_template($single_template) {
     global $post;
     $plugin_path = plugin_dir_path( __FILE__ );
     if ($post->post_type == 'press_release') {
        if(file_exists($plugin_path . 'views/single-press_release.php')) {
            $single_template = $plugin_path . 'views/single-press_release.php';
            echo 'EXISTS! ' . $plugin_path . 'views/single-press_release.php';
        }
     }
     return $single_template;
}
add_filter( 'single_template', 'single_press_release_template');

The file single-press_release.php (located in the 'views' plugins directory) contains this code:

/**
 * Single Press Release
 *
 * @package WordPress
 */

<?php

echo 'Hello World';

?>

The result I get is a page without any main content (there is no 'hello world' text at all) but I can see the echo 'EXISTS! ' . $plugin_path . 'views/single-press_release.php':

blank main content

What am I doing wrong?

Thanks a lot!

I'm trying to create a single template for the custom post type posts called 'press release' from a plugin.

This is the code I added to my plugin:

function single_press_release_template($single_template) {
     global $post;
     $plugin_path = plugin_dir_path( __FILE__ );
     if ($post->post_type == 'press_release') {
        if(file_exists($plugin_path . 'views/single-press_release.php')) {
            $single_template = $plugin_path . 'views/single-press_release.php';
            echo 'EXISTS! ' . $plugin_path . 'views/single-press_release.php';
        }
     }
     return $single_template;
}
add_filter( 'single_template', 'single_press_release_template');

The file single-press_release.php (located in the 'views' plugins directory) contains this code:

/**
 * Single Press Release
 *
 * @package WordPress
 */

<?php

echo 'Hello World';

?>

The result I get is a page without any main content (there is no 'hello world' text at all) but I can see the echo 'EXISTS! ' . $plugin_path . 'views/single-press_release.php':

blank main content

What am I doing wrong?

fixed formatting
Source Link
cjbj
  • 15k
  • 16
  • 42
  • 89

I'm trying to create a single template for the custom post type posts called 'press release' from a plugin.

This is the code I added to my plugin:

function single_press_release_template($single_template) {
     global $post;
     $plugin_path = plugin_dir_path( __FILE__ );
     if ($post->post_type == 'press_release') {
        if(file_exists($plugin_path . 'views/single-press_release.php')) {
            $single_template = $plugin_path . 'views/single-press_release.php';
            echo 'EXISTS! ' . $plugin_path . 'views/single-press_release.php';
        }
     }
     return $single_template;
}
add_filter( 'single_template', 'single_press_release_template');

The file single-press_release.phpsingle-press_release.php (located toin the 'views' plugins directory) contains this code:

/**
 * Single Press Release
 *
 * @package WordPress
 */

<?php

echo 'Hello World';

?>

The result I get is a page without any main content (there is no 'hello world' text at all) but I can see the echo 'EXISTS! ' . $plugin_path . 'views/single-press_release.php''EXISTS! ' . $plugin_path . 'views/single-press_release.php':

blank main content

What am I doing wrong?

Thanks a lot!

I'm trying to create a single template for the custom post type posts called 'press release' from a plugin.

This is the code I added to my plugin:

function single_press_release_template($single_template) {
     global $post;
     $plugin_path = plugin_dir_path( __FILE__ );
     if ($post->post_type == 'press_release') {
        if(file_exists($plugin_path . 'views/single-press_release.php')) {
            $single_template = $plugin_path . 'views/single-press_release.php';
            echo 'EXISTS! ' . $plugin_path . 'views/single-press_release.php';
        }
     }
     return $single_template;
}
add_filter( 'single_template', 'single_press_release_template');

The file single-press_release.php (located to the 'views' plugins directory) contains this code:

/**
 * Single Press Release
 *
 * @package WordPress
 */

<?php

echo 'Hello World';

?>

The result I get is a page without any main content (there is no 'hello world' text at all) but I can see the echo 'EXISTS! ' . $plugin_path . 'views/single-press_release.php':

blank main content

What am I doing wrong?

Thanks a lot!

I'm trying to create a single template for the custom post type posts called 'press release' from a plugin.

This is the code I added to my plugin:

function single_press_release_template($single_template) {
     global $post;
     $plugin_path = plugin_dir_path( __FILE__ );
     if ($post->post_type == 'press_release') {
        if(file_exists($plugin_path . 'views/single-press_release.php')) {
            $single_template = $plugin_path . 'views/single-press_release.php';
            echo 'EXISTS! ' . $plugin_path . 'views/single-press_release.php';
        }
     }
     return $single_template;
}
add_filter( 'single_template', 'single_press_release_template');

The file single-press_release.php (located in the 'views' plugins directory) contains this code:

/**
 * Single Press Release
 *
 * @package WordPress
 */

<?php

echo 'Hello World';

?>

The result I get is a page without any main content (there is no 'hello world' text at all) but I can see the echo 'EXISTS! ' . $plugin_path . 'views/single-press_release.php':

blank main content

What am I doing wrong?

Thanks a lot!

Source Link

Single_template for a custom post type created from a plugin is returning an empty page

I'm trying to create a single template for the custom post type posts called 'press release' from a plugin.

This is the code I added to my plugin:

function single_press_release_template($single_template) {
     global $post;
     $plugin_path = plugin_dir_path( __FILE__ );
     if ($post->post_type == 'press_release') {
        if(file_exists($plugin_path . 'views/single-press_release.php')) {
            $single_template = $plugin_path . 'views/single-press_release.php';
            echo 'EXISTS! ' . $plugin_path . 'views/single-press_release.php';
        }
     }
     return $single_template;
}
add_filter( 'single_template', 'single_press_release_template');

The file single-press_release.php (located to the 'views' plugins directory) contains this code:

/**
 * Single Press Release
 *
 * @package WordPress
 */

<?php

echo 'Hello World';

?>

The result I get is a page without any main content (there is no 'hello world' text at all) but I can see the echo 'EXISTS! ' . $plugin_path . 'views/single-press_release.php':

blank main content

What am I doing wrong?

Thanks a lot!