Change password protect text in a child theme? (7 posts)

  1. edhans
    Posted 3 years ago #

    I'd like to change the text on password protected posts. The thread here seems to cover the technical details (I guess it works on WP 3.5+) but I don't want to change my theme's function.php file. I would rather do it in my child theme, but it has no function.php file and not sure how to use the code in the linked thread to a new file and have it work properly.

    Thanks for any assistance.

  2. Clayton James
    Posted 3 years ago #

    "Unlike style.css, the functions.php of a child theme does not override its counterpart from the parent. Instead, it is loaded in addition to the parent’s functions.php. (Specifically, it is loaded right before the parent’s file.)"

    Source: http://codex.wordpress.org/Child_Themes#Using_functions.php

  3. leejosepho
    Posted 3 years ago #

    That is simple to do, and I will be at my other machine in the morning where I can post the few lines needed if you do not have it done by then.

  4. leejosepho
    Posted 3 years ago #

    Here is all I needed to add to functions.php inside my Twenty Twelve Child Theme:

    // change password message for protected page/s
    function change_pw_text($content) {
    $content = str_replace(
    'This post is password protected. To view it please enter your password below:',
    'Hint: Tell our system to show you, and it will.',
    return $content;
  5. edhans
    Posted 3 years ago #

    Thanks. That code worked. I didn't have a function.php file so created one. I added:


    to the top to get it to work but in the regular function.php file, I didn't see a closing tag. Is there one for the <?php tag?

  6. Clayton James
    Posted 3 years ago #

    I don't believe a closing tag is required.

  7. leejosepho
    Posted 3 years ago #

    ... and if you might ever use one anyway, be sure to never have any spaces or line breaks after the close.

Topic Closed

This topic has been closed to new replies.

About this Topic