Outputting post_meta as formatted text - php

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.

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.

Wordpress - print Custom Field with HTML content

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'));?>

Strip blank <p> tags from WordPress post Export

I'm trying to export all my posts in WordPress to integrate the same in HubSpot COS.
Though I have a some issues in formatting of posts.
There are a few <p>tags, which I want to strip.
Here's a DOM screenshot of a post.
The <p> tags without any content needs to stripped off.
The issue I'm having in HubSpot is, HubSpot creates the entry excerpt as the first paragraph of the post. Since my first paragraph is blank there is no excerpt in HubSPot.
Thoughts on tackling this?
You could use a regex
$content=preg_replace("/<p[^>]*>\s*<\/p>/isU","", $content);
Hubspot does not use the first paragraph as the excerpt
You can select were you want your excerpt to end by going to the blog editor, moving your cursor to the line where you want your excerpt to end, then click
Insert > Read More Separator
Done

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.

DB content not coming into tinyMCE textarea

My tinyMCE editor is showing up just fine, but in the form I have a select box and according to what you choose, the textarea is filled with content accordingly.
Like if I choose PHP, then the description for PHP comes into the textarea. It works without tinyMCE, but when I add tinyMCE, nothing shows up in the textarea.
TinyMCE does not display the content of the textarea in real-time. It reads the content on start, and saves it at the end of the work. All the edit work takes place in an iframe element, created on the fly by Tiny. If you update the textarea, you must ask TinyMCE to refresh itself.
In a few minutes I will look up the exact method for you. (It was long time ago when I was using TinyMCE, so I forgot the method names.)
[few minutes have passed..]
Look at the documentation: http://www.tinymce.com/wiki.php/How-to_load/save_with_Ajax_in_TinyMCE
You just need to call setContent method on the TinyMCE editor, instead of (or in addition to) setting the new text in the textarea.
with tiny mce sometimes it dependes the plugins that you in the Init.
Try Removing all the plugins and add one by one and see if this helps you in finding a better solution for this.
Some plugins like the media can strip and not allow tags in the text area, so the textarea is empty if tiny mce doens't allow that tags, or add valid_elemens:'[]' and try if it shows something.
Good luck

Categories