So i am trying to have a custom textarea where users can do things like bold text, add ul's,link tags and so on. For all of this I am using the wp_editor() function inside wordpress, like this.
$content = "";
$editor_id = "e_id";
$editor_settings = array(
'teeny' => true,
'editor_height' => 160,
'quicktags' => array( 'buttons' => 'strong,em,del,close' ),
'media_buttons' => false );
wp_editor( $content, $editor_id ,$editor_settings );
So everything such as adding links bolding text and so on works just fine.
My issue is accessing the text that was just typed into this field.
I tried accessing the text using JQuery, by alerting the value of the textarea/contenteditable area like so...
alert($("#e_id").val());
but each time the result is always an empty string and not the newly typed text.
How do I get a hold of the newly typed text
So while looking around on here I found a similar question related to the Wordpress wp_editor() function. Here
Apparently there is a special tinyMce function used to access wp_editor() or the tinyMce editor's text/content.
So using this inside inside my onSubmit handler:
tinyMCE.activeEditor.getContent()
I was able to get content or text that was entered into the wp_editor().
Also another good post on the subject.
Related
Within Wordpress, I am attempting to add a text box to a page where users can paste data. Within this box I simply want to give them ability to spell check the pasted text, preferably using the built in wp_editor functionality.
I've tried adding code below to the page, however all wp_editor buttons are still present including 'add media':
<?php wp_editor( $content, $editor_id, $settings = array() ); ?>
Thank's in advance!
The wp_editor() function has many options. For instance, you can turn off the media insert buttons:
$settings = array( 'media_buttons' => false );
wp_editor( $content, $editor_id, $settings );
I don't think WordPress does spellchecking. Are you sure this isn't a function of your web browser or operating system?
I have created a wordpress theme, in the wordpress theme customizer I have added a couple of text areas where a user can input their own CSS or JS to be added to the head.
The placement of the text area is fine, i.e. when a user adds code it is displayed on the right place in the page, however it is being formatted differently.
For example, I add the following code to one of the textareas:
jQuery(document).ready(function($){
$('full_page').css('min-height',($(window).height()-195));
});
And in my theme it is outputted like this:
jQuery(document).ready(function($){
$('full_page').css('min-height',($(window).height()-195));
});
As you can see, the ' is being replaced with '
Here is the code in my customizer.php file to create the text area:
$controls[] = array(
'type' => 'textarea',
'setting' => 'js',
'label' => __( 'Custom JS', 'skizzar_bootstrap' ),
'subtitle' => __( 'You can write your custom JavaScript/jQuery here. The code will be included in a script tag appended to the top of the page.', 'skizzar_bootstrap' ),
'section' => 'advanced',
'priority' => 6,
'default' => '',
);
Is there a way to stop this formatting from happening?
Wordpress is HTML encoding all of the special characters. If the user enters HTML, then the result should be fine. It is not intended for Javascript.
Allowing the user to enter Javascript like this a big security hole. The script could do anything, not necessarily all pleasant.
If you really want to do this and it's your code echoing the Javascript in your theme, run it through htmlspecialchars_decode before you display it. That PHP function will convert the HTML codes back to characters.
Since none of plugin works with new wordpress and buddypress for rich text editor I have started to implement it myself manually directly into the theme.
After using wp_editor() I got the editor on my fourms and it is posting forums content well without issue. However when I am trying to edit forums post it is not loading any content into the text editor. I am using below code if anyone can help me.
$content = bp_the_topic_text();
$args = array(
'quicktags' => true,
'editor_class' => 'frontend',
'textarea_rows' => 5,
'tabindex' => 1
);
wp_editor( $content, 'topic_text', $args);
This doesnt load the forum post content just wonder. I have tested with the sting and just works fine it loads the string but not the actual content with the function. I dont know either this is the right function to get the content or not.
I am getting output like
I want show content in inside of editor.
Thanks a lot in advance.
bp_the_topic_text() echoes the value. It's a wrapper for bp_get_the_topic_text(), which returns the value. So you should do this instead:
$content = bp_get_the_topic_text();
I'm working on a site for a client that runs a social ransom style blog. This is where the user has to click one of the social media buttons to get access to the content.
However, she is now going to use the OnePress Social Locker Plugin for wordpress which works by wrapping the content in specific tags, like so:
[sociallocker] Content Here will Be Locked [/sociallocker]
At the moment she already has her own custom shortcode in place which works like this:
[socialLock url="http://example.com" text="Click here to view content"] Content here will be locked [/socialLock]
The problem is that she has over 2,300 pages on her blog and to change every single one indv. through the dashboard will take ages and this is not a by the hour pay contract.
I thought that I would be able to pass the current shortcode into the new one like so:
function parseShortcode_func( $atts ) {
$atts = shortcode_atts( array(
'link' => '',
'text' => 'default text'
), $atts );
return "[sociallocker] {$atts['text']} [/sociallocker]";
}
add_shortcode( 'socialLock', 'parseShortcode_func' );
However that just outputs
[sociallocker] Click here to view content [/sociallocker]
Has anyone got any ideas how to parse this second shortcode within a shortcode?
The do_shortcode() function will reparse your output string.
return do_shortcode("[sociallocker] {$atts['text']} [/sociallocker]");
Is there a way that I can have wordpress let me use its wp_editor in the theme options panel. I am making my first WP theme and I am a little confused. I need to have some fields on my custom homepage be editable but not others and the ones that I do want editable need to be controlled via a html editor to preserve text formatting.
I am currently using a textare field like this...
//Paragraph1
$options[] = array( "name" => "paragraph1",
"desc" => "Enter text for paragraph1 on the homepage",
"id" => $shortname."_paragraph1",
"std" => "",
"type" => "textarea");
Could somebody please tell me what I would do to make a html editor appear under theme options instead of a textarea
Thanks
Just include/output the wp_editor function in your switch case for that specific textarea type/id instead of your usual html code.
For usage of the wp_editor see = http://codex.wordpress.org/Function_Reference/wp_editor