1

So, I'm trying to prepopulate a specific page with HTML/CSS every time the page template is used. I've found this thread that was very helpful with how to do it, and this one was very helpful on clearing up the confusion about how to use the parameter for the function. But I cannot get the first if statement to be read, here is my function:

/* Fill Assessments page with HTML contents */
add_filter('default_content', 'my_editor_content');
function my_editor_content( $content )
{
    if (is_page_template(ABSPATH.'wp-content/themes/sydney/page-templates/page_assessments.php'))
    {
        $content = 'HELL YEAH';
    }
    else
    {
        $content = file_get_contents(ABSPATH.'wp-content/themes/sydney/assessments.html');
    }
    return $content;
}

But I can't get the file to read the first if statement. I've also tried:

if (is_page_template('path/page-template.php')

But nothing worked to read that so far. How can I achieve it? Thanks!

  • have you read developer.wordpress.org/reference/functions/is_page_template/… ? in your case this could be: is_page_template( 'page-templates/page_assessments.php' ) – Michael Jun 6 '18 at 3:31
  • Do you want to add them to an entire page or just a section of that page? – Nathaniel Flick Jun 6 '18 at 3:45
  • @NathanielFlick whole page should be fine. – Luke Perez Jun 6 '18 at 4:31
  • @Michael I think my post references exactly that, I have tried exactly that, without using ABSPATH. I don't know what exactly is wrong here. – Luke Perez Jun 6 '18 at 4:32
  • 1
    this filter default_content is not usefull for you because it is called when you click on "new page" then before the user choose the template. another solution could be JavaScript that add content when the user change the template. – mmm Jun 6 '18 at 7:13

Your Answer

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

Browse other questions tagged or ask your own question.