Wordpress - print Custom Field with HTML content - php

I try to import HTML into wordpress WYSIWYG custom fields and later display it correctly.
The values get written by the importer, but when I try to edit such a content type, the WYSIWYG editor is spammed with html-tags.
I tried different variants to escape the htmlspecialchars. With no succes. The WYSIWYG editor also displays those, instead of formatting the text.
Also, when i do print_custom_field in my template, the html does not get rendered, but displayed again. Obviously not what I would want.
All related content types are created with custom content type manager
https://code.google.com/p/wordpress-custom-content-type-manager/
My Question:
Is it a bad idea in general to import html-snippets from a (trusted) external source?
How can I trick the output from worpdress into rendering html for certain fields, instead of displaying it.

This was actually related to the view layer. Since that was not my business, I didn't care at first.
Turns out, that one has to us htmlspecialchars_decode in the templates, because the wordpress-api does htmlspecialchars on import.
The following code works fine
<? print htmlspecialchars_decode(get_custom_field('foo'));?>

Related

wordpress deletes <sup> on save comment

I'm trying to implement an WYSIWYG editor to my WP comment section. I experience many difficulties with saving the HTML data in the WordPress database. WP strips many of the HTML tags automatically. I was able to restore the tags trough the 'preprocess_comment' filter. I added the wpautop() filter to the content. Now the line breaks are appearing. But when I want to use the tag, WordPress deletes is too.
I use the Trumbowysiwyg js solution to replace the default comment textarea with the wysiwyg editor. When using the editor, the HTML code looks nice. It has all the HTML tags but after saving the comment, these tags are stripped. Can someone tell me how to allow HTML comments to be saved in the database?
WordPress keeps a list of allowed tags which you can use in comments, surely you do not want users to post any html they want. So I suggest you edit the allowedtags so they will not be removed.
add_action('comment_post', 'allow_more_tags');
function allow_more_tags() {
global $allowedtags;
$allwedtags['sup'] = array('class'=>array());
}
Like this you can add any tags you like and even allow certain classs to be added to them.

Outputting post_meta as formatted text

I had a similar question just yesterday, which I resolved, but it lead me to another problem still. I got the fields using the wp_editor to save the content as formatted, but now I can't seem to make it display on the page in the same way.
wp_editor(htmlspecialchars_decode($trmet_itinerary) , 'trmet_itinerary', array(
"media_buttons" => true
));
is being used to create the wysiwyg editor in my custom Meta Box, which saves good to the database. But it outputs that text to a custom field with markup, which I can't seem to get to display correctly.
For example, entering the following via the admin panel,
This is the overview of content!
outputs, This is the <strong>overview</strong> of content! to it's corresponding custom field.
I've tried variations of <?php echo get_post_meta($post->ID, 'trmet_overview', true);?> to get it to display on the front-end, but nothing does the trick. I know it has something to do with converting the characters and also tried variations of wpautop to no avail.
I hope this make sense. In summary, I want to output rich text entered in wp admin to the front-end as-is with not just paragraphs or breaks, but all content therein such as <h1> tags, bold, italic and the like.

wordpress page.php styling and markup

I have a couple of questions related to building a custom theme with Wordpress.
1) If the website is made up of pages, I can use page .php to run the LOOP and retrieve content. In this case, is it OK to paste the content (of each page) using the backend of word press - I.e. paste all content and HTML markup into the 'text; . Is this a reliable way to enter content and accompanying markup into the database?
I guess the advantage is that users will then be able to edit the content themselves using the visual Tab.
Many thanks,
P
Well this not a recommended way to do it, but yes the editor is there for the same purpose. I wont be using it this way, because in my experience wordpress editor often acts weird with html. By default auto paragraphs are enabled, so everything gets in its own paragraph, even if you disable auto paragraph it still has some issues. For instance if you add html in the text tab, and then goto visual tab and switch back to html, and save the same html, this time it would be styled differently. Secondly its also not good to allow users to add html from a security POV and you cant guarentee the consitency of the website.
I would recommend using custom fields instead and fetch these custom fields in the through your theme files.

Wordpress,how can I convert textareas to use a wysiwyg editor?

I have a question about wordpress. I am creating a web form for branch managers to enter data into a database, one of the fields can contain bullet points so I need to use an editor that will allow the user to use bullets and then convert it to html like the way wordpress handles posts. Is there a way to make text areas use the tinymce editor? I tried using mceTextarea but it didn't do anything. Anyone know how to add editor options to textareas?
(Making this an answer so others can find it.)
WordPress has a function called wp_editor() that creates a WYSIWYG editor anywhere you need one.

How can I insert XML example code inside a Joomla article?

I'm building a site in Joomla 2.5 that covers topics related to programming.
I have tried various plugins and I had no problem to insert java, javascript and php code inside my articles (the classic view with indented line number)
The problem arises when I try to insert XML.
Currently I'm using the plugin Code HighLight (but I found the same thing with other plugins).
To insert the XML code in my article I have to do so in my article:
{code class="brush: xml;"}CODE HERE{/code}
The problem is that, if I insert Java or Js or php code I have no problem, but if I try to insert XML code in this way in my article it appears bad (parts missing)
I also tried to plug it directly into HTML (by pressing the button HTML editor TinyMCE) but, once inserted, when I come back to the WYSIWING editor, this problem occurs again.
In the plugin instruction I can read:
BEWARE of your visual editor (JCE or JCK for example), it can place tags in your code, after this code became invalid!
I use TinyMCE as editor (it is always a WYSIWYG editor) and seems that this is the problem infact if I disable the graphical editor (inside the Joomla global configuration setting the editor as void) or if I choose the CodeMirror editor (that it is a simple HTML editor, not a WYSIWING editor) if I insert the XML code in te previus way...work well !!!
The problem is that I need a graphical editor (to set the styile of my articles text) and at the same time I need to insert XML code snippet inside my articles...
I have observed that behavior using many code snippet plugin...the problem is not a plugin problem but I think it is related to the WYSIWING editor that seems to insert it's tag inside the XML code or at least makes it dirty (eliminates parts and inserts some tags like )
What can I do to have XML code snippet in my articles and at the same time have a WYSIWING editor? (if the problem is TinyMCE I can also try some other WYSIWING editor...)
Thanks
Andrea
You can give extension for code display a try.
Another solution I read about was
1) activate Content - Code Highlighter (GeSHi)
2) generate your code here
3) C&P the generated code in the WYSIWYG editor
You can do either one or the other...you cannot do both.
My suggestion is this: do the WYSIWYG part of the page...toggle the WYSIWYG editor off...then insert your xml...and NEVER go back to that page with the WYSIWYG editor on again.
I have had the same issues inserting xml in my website.
If you have logged out of joomla and log back in...the default is the WYSIWYG editor.
So if you open an article/module/plugin and it opens in WYSIWYG, it clears the xml that you have inserted into the page. Simply toggle the WYSIWYG editor so that it is off...then CLOSE the article (DO NOT SAVE & CLOSE)...just close. Then open the article/module/plugin again...it should be the html editor only...and code away.
I hope this helps.

Categories