How to add TinyMCE to a
-
The Plugin works just fine from the WordPress dashboard, but I’m at the moment using Contact form 7 for people to submit article to me through that, and the plugin doesn’t add the buttons to the text area, is there a way I can add it to that page only? or even add it to every text box on the site? like comment section and other pages?
I’m trying to make it show up on “Full Article Content” on this page: https://www.mustknowbefore.com/add-article/
And I would like to applaud you what a wonderful plugin.
Thanks
-
Okay… here we go…
1. In your admin panel, on the contact form you have created, you are going to need to add an ID to the textarea.
Here is what mine looked like:
<p>Your Name (required)<br /> [text* your-name] </p> <p>Your Email (required)<br /> [email* your-email] </p> <p>Subject<br /> [text your-subject] </p> <p>Your Message<br /> [textarea textarea-354 id:my_test] </p> <p>[submit "Send"]</p>
You can also create a new textarea by clicking the “Generate Tag” button and choosing “Textarea”… then assign it an ID. You can see how mine has an ID of
my_test
. I would name yours the same.. as the following code depends on this name.2. Next.. we need to add this code to your functions.php file in your child theme folder. You should already have the following in this file:
<?php ?>
So, we want to REPLACE that with the following code:
<?php function add_tinymce_textarea($content) { if (is_page(187)) { $new_content = wp_editor('','my_editor'); $content = $content . $new_content; return $content; } } add_filter('the_content', 'add_tinymce_textarea'); function my_wp_head() { if (is_page(187)) { wp_enqueue_script('jquery'); ?> <script type="text/javascript"> jQuery(document).ready(function($){ content = $('#wp-my_editor-wrap'); $('#my_test').replaceWith(content); }); </script> <?php } } add_action('wp_head','my_wp_head'); ?>
Remember to use the code editor as I suggested above.
3. Save your
functions.php
file to your child theme.Now, re-visit the page from the front-end of the website and you should see the tinymce editor.
Yes it worked perfectly, excellent.
Can I add this to the main theme or do I still have to use the child theme?
And if so do I just need to copy that extra function into the main theme?
Thanks
I just tried cut the script inside functions.php (childtheme) to the main themes’s functions.php and it caused an error “Parse error: syntax error, unexpected ‘<‘ in /home3/abbsjr/public_html/******/wp-content/themes/surfarama/functions.php on line 82”
Or how do I reset the settings for the theme? I didn’t understand what you meant before by resetting some settings?
If you add it to the main theme… it is going to be overwritten the next time you update your theme.
When you update a theme… all core theme files are overwritten during the update. If you add new lines of code to one of these files… it will be lost the next time the theme is updated.. because there is no possible way the theme author can know of your unique changes.
This is why we always use a child theme. It allows us to add all our custom functions without running the risk of them being overwritten.
I just tried cut the script inside functions.php (childtheme) to the main themes’s functions.php and it caused an error
This is most likely because you copied and pasted the code into an incorrect position in your main theme functions.php file.
I would need to see the file in it’s entirety to see what you did. However, I would still strongly discourage moving it to your main theme, for the reasons listed above.
Alright thankss so much josh you can close the topic now, I understood what you mean by resetting them, bye ??
I just tried changing colors and etc stuff from theme settings (while on the childtheme) and that works, but I’m having the issue that the text on my site isn’t showing under the title on the homepage like it did on the main theme
the reason I would like to use the main theme is cause of this mainly, I don’t want to bump into more problems than what I started with, here’s the functions.php if you can tell me where to paste it I would be very grateful:
Apologize for the hassle
No hassle whatsoever.
Please forgive my brevity.. it’s late here.
You are still using your main theme. All of your main theme options and admin settings should still function exactly as they did before. The only thing you are doing with a child theme is extending the functionality of your main theme in a way which is safe during theme updates.
This is the 100% WordPress accepted method for extending functionality of a main theme. Again, the main theme is still the foundation of your site. One way of thinking is that you are actually using both the main theme and the child theme simultaneously.
Again, if you copy those functions into your main theme… they will be deleted the next time you update your theme. All theme files are over-written during the update process. This will effectively remove any custom code you have added/removed. Hence; child themes.
So, what is the specific issues you are facing with using the child theme?
That’s my problem, the text under the title doesn’t show on the homepage
Okay…
Temporarily remove those functions from your child theme.
Get it back to just<?php ?>
Now, re-activate this child theme.
Does the content appear normally on your main page now?
Sorry for the late reply I didn’t get an email notification that you responded to me,
Yes I just removed the functions from the child theme and it appears normally just like it should
Okay.. not really sure why that’s happening. But, let’s redo the code to run the page conditional FIRST… then modify accordingly.
Try this instead:
<?php if (is_page(187)) { function add_tinymce_textarea($content) { $new_content = wp_editor('','my_editor'); $content = $content . $new_content; return $content; } add_filter('the_content', 'add_tinymce_textarea'); function my_wp_head() { wp_enqueue_script('jquery'); ?> <script type="text/javascript"> jQuery(document).ready(function($){ content = $('#wp-my_editor-wrap'); $('#my_test').replaceWith(content); }); </script> <?php } add_action('wp_head','my_wp_head'); } ?>
Just pasted it in functions.php in the child theme and it didn’t work, well it worked but in the sense that the text under the titles show, but the tinymce don’t appear in the box, you can see for yourself, I activated the child theme on https://www.Mustknowbefore.com and currently using it, it currently on the last php setting you gave me ^
Okay… let’s try adding one more conditional.
If this doesn’t work.. then I’ll probably need access to your site for some trial and error. If this is an option, you can create me a temp admin account, and send the login credentials discreetly via my contact form.But, let’s try this first:
<?php if (is_singular() && is_page(187)) { function add_tinymce_textarea($content) { $new_content = wp_editor('','my_editor'); $content = $content . $new_content; return $content; } add_filter('the_content', 'add_tinymce_textarea'); function my_wp_head() { wp_enqueue_script('jquery'); ?> <script type="text/javascript"> jQuery(document).ready(function($){ content = $('#wp-my_editor-wrap'); $('#my_test').replaceWith(content); }); </script> <?php } add_action('wp_head','my_wp_head'); } ?>
What we have done is added an is_singular() conditional… which should not run on your homepage. (This is what is removing the content from those info blocks).
The issue is actually not just that sorry, I should have made it clearer, the text not only doesnt show on the homepage, but also in the post itself, so if I click on the title that’s on the homepage, and I go to the post, it’s empty, so if you have another code give it to me, or if you’re more confused now, I got no problem, I made you a temp account but I don’t know how to send it, whats your email?
- The topic ‘How to add TinyMCE to a’ is closed to new replies.