• Resolved thymotep

    (@thymotep)


    Hello everyone ??

    After a search time, without finding a solution, I just wonder if it is possible, from a plugin, edit a theme file?

    I created a plugin that improves adding comments, I add new fields with no problem, but I would also like to customize the display (comments.php in theme).

    During my research, I came across this article ( https://stackoverflow.com/questions/4647604/wp-use-file-in-plugin-directory-as-custom-page-template ), but here is not, I do not seek to create a page template, but to overload a theme file from my plugin.

    I do not even know if this is possible, but thank you in advance for your help.
    Thymotep

Viewing 2 replies - 1 through 2 (of 2 total)
  • Richard

    (@richardcoffee)

    You should be able to change it using the ‘comments_template’ filter. Something like this might work for you:

    add_filter('comments_template','replace_comments_php');
    function replace_comments_php($template) {
      return $path_to_new_comments_php_file;
    }

    Be aware this will only work if the theme is using get_template_part(‘comments’);

    Thread Starter thymotep

    (@thymotep)

    This is exactly what I needed! The theme uses the well comments_template feature!

    Thank you a lot ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Can I override a theme file from my plugin?’ is closed to new replies.