WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. edhans
    Member
    Posted 1 year 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. ClaytonJames
    Member
    Posted 1 year 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
    Member
    Posted 1 year 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
    Member
    Posted 1 year 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.',
    $content);
    return $content;
    }
    add_filter('the_content','change_pw_text');
  5. edhans
    Member
    Posted 1 year ago #

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

    <?php

    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. ClaytonJames
    Member
    Posted 1 year ago #

    I don't believe a closing tag is required.

  7. leejosepho
    Member
    Posted 1 year 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