WordPress.org

Forums

Explanatory Dictionary
[resolved] Detect word in themplate files (12 posts)

  1. cedric.charles
    Member
    Posted 1 year ago #

    Hi !

    I'm using your great "Explanatory Dictionary". Thanks for this !

    I would like to know if it's possible to automatically detects words directly in the theme ? Not in the WordPress WYSIWYG ?

    Thanks a lot,
    Cédric

    https://wordpress.org/plugins/explanatory-dictionary/

  2. cedric.charles
    Member
    Posted 1 year ago #

    I've achieved that by wrapping my text (<p></p> for example) around
    <?php echo $dictionary->add_explanatory_dictionary_words(<<<HEREDOC ............. ); ?>)
    after having instantiated
    $dictionary = Explanatory_Dictionary::get_instance();

    The problem is that since I'm using php code in my template, I can't wrap all my html content in one echo $dictionary->add_explanatory_dictionary_words... but need multiple one. Unfortunately, calling multiple times echo $dictionary->add_explanatory_dictionary_words doesn't work, I can only have the definition of the last word of the page... Not the other ones...

    Could you help me ?
    Thanks

  3. EXED internet
    Member
    Plugin Author

    Posted 1 year ago #

    As for now this is a no, it is meant to only show words inside the content of the page.

    Maybe in a future release but I don't know that for sure yet.

  4. cedric.charles
    Member
    Posted 1 year ago #

    Hi !

    Thanks, I figure out how to do that, and it works ;) !

    Have a nice day !

  5. Gabums
    Member
    Posted 1 year ago #

    @cedric.charles

    Hi! I'm having the same issue you were having. Could you please explain to me how you ended up resolving it? Thanks so much!

    Cheers!
    Gabrielle

  6. cedric.charles
    Member
    Posted 1 year ago #

    Hi @Gabums,

    I'll answer you in 2 hours and a half :) !

    See you !

  7. Gabums
    Member
    Posted 1 year ago #

    Thank you!

  8. Gabums
    Member
    Posted 1 year ago #

    @cedric.charles!

    Do you have a minute to explain what you did yet please???

  9. cedric.charles
    Member
    Posted 1 year ago #

    Hi @Gabums !

    Sorry, I had a lot of work and totally forget this thread. Hopefully you ask it again ;) !

    To have a lot of template content processed through the plugin :

    1. Let's say the template is "mytemplate.php". Create a new PHP file and call it like you want (here I call it "tobetranslated.php").

    2. Put the PHP of "mytemplate.php" that need to be processed in "tobtranslated.php".

    3. Replace that content (in "mytemplate.php") by this piece of code :

    <?php
       			$dictionary = Explanatory_Dictionary::get_instance();
       			$content = load_template_part($template_path, $template_name);
       			echo $dictionary->add_explanatory_dictionary_words($content);
          ?>

    load_template_part($template_path, $template_name) : First argument is the path (folder etc), second argument is the name of the file (here "tobetranslated.php")

    ATTENTION : everything in "tobetranslated.php" will be processed. So If you have register the word "test" in the admin and you have a HTML class which is class="test", the class will be processed and so the HTML will be wrong !

    Tell me if it works ;)

    Have a nice day !
    Cédric

  10. Gabums
    Member
    Posted 1 year ago #

    No worries @Cedric! Thanks for your response. :)

    So just to be sure I am understanding you correctly. All I need to do is make a copy of "mytemplate.php" and rename it "tobetranslated.php". Then I take all the content in "mytemplate.php" and replace it with the code you provided? (with correct paths of course)

    Thanks again!

  11. Gabums
    Member
    Posted 1 year ago #

    So i got it working! The way you did it didn't quite work for me but I was able to utilize some of your code and place it elsewhere. Incase anyone else is trying to do this too, here it is:

    The way my theme template was calling the text was by using

    echo do_shortcode ( $options['stb_content'] );

    I then took that code and added

    echo do_shortcode($dictionary->add_explanatory_dictionary_words ( $options['stb_content'] ));

    Making sure I placed

    $dictionary = Explanatory_Dictionary::get_instance();

    Beforehand.

    Hope that helps someone.

    Thank you @cedric for your help as well!

  12. cedric.charles
    Member
    Posted 1 year ago #

    Yes it's exactly the way it works. Unfortunately, you can place the following code only once per page

    $dictionary = Explanatory_Dictionary::get_instance();

    So If you have multiple shortcode, the_content, the_excerpt, etc... To be processed through the plugin, you just put all these codes in an other PHP file and call this template part inside the $dictionary->add_explanatory_dictionary_words code :) !

    Glad I can help :) !

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Explanatory Dictionary
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.