• I’m wondering what is the best way to get round the “WordPress ate my code” problem.

    The problem that I have is that if I want to use WP to create a web site rather than just a simple blog (http://www.windermerelogcabin.com/) I need more control over layout than the default TinyMCE editor allows, and I also want to be able to add iframes so I can have a Google map, or a Google Spreadsheet containing availability info etc.

    It would appear that the limitation is intentional in order to stop people injecting code into a site via comment posting.

    Now I can add an iframe or additional code in the html window, but if I even look at the post in the Visual editor the code gets removed.

    I CAN stop this happening on a tag by tag basis by using the TinyMCE Valid Elements plug in, but it’s a bit cludgy, and I wonder if that is storing up a future problem from hackers? (Do I need to worry?)

    I tried using the FCKeditor plug-in to replace WP but that gives problems here uploading images.

    I wonder how other WordPress users get round the need to add valid html code, but at the same time allow non-techy users to add images and text without destroying it?

    It seems to me that this is a bit of an Achilles heel for WordPress as far as website development goes – I’m moving along the change curve and have gone from “uninformed optimism” to “informed pessimism” now.

    I’m hoping that someone can help me along to “informed optimism”

Viewing 7 replies - 1 through 7 (of 7 total)
  • I’ve had this problem when switching between the HTML and Visual editor. Try going into your user settings and turning the Visual Editor off.

    The control you want means learning how WordPress functions under the hood (that is, getting away from the admin area.) The kind of functionality you are looking for can be found in Page Templates. Duplicate the Page.php file of a theme, rename it to whatever you want and add

    <?php
    /*
    Template Name: WhateverItsCalled
    */
    ?>

    to the very top. You can write whatever HTML you want in it around the post template code (or delete the post template code, whatever.) Whatever page you intend to use that code on, when you edit it you’ll be able to choose the new page template from a dropdown menu on the right side of the screen.

    Thread Starter pommie

    (@pommie)

    Thanks guys.

    @nouvellerI’m afraid I need to allow my non-techy users to use the Visual Editor so I can’t turn it off (and I don’t really want to either – I just want it to stop destroying my code!)

    @jdb – can see how that might help in some ways, but if I need to mix html and text in a page my non -techy users can then not edit the text without editing mynewage.php – correct?

    I am hoping there might be an answer that preserves the flexibility of having a text editor with formatting and the ability to add html coding.

    Before I found WordPress I would never have imagined in a million years that this would be a problem. 🙂

    Consider learning about WordPress filters (http://codex.wordpress.org/Plugin_API#Filters) and Plugin Development. Many plugins use some sort of bbcode shorttag in the text editor which will be replaced by content specified by your plugin.

    For example:
    This is text in my text editor. I am writing a page and I want to include a code snippet here so I will put a shorttag here which will be replaced. [myplugin snippet="1"]

    check it out here http://codex.wordpress.org/Using_the_gallery_shortcode

    hope this helps

    Thread Starter pommie

    (@pommie)

    Thanks for that suggestion – now we are getting away from my comfort zone 🙂

    I will have to have a stiff drink and see if I can make some sense of those links 🙂

    Using page templates won’t affect anything that’s added by the WYSIWYG editor. It will let you structure, organize and style how that content is displayed and also lets you add content that can’t be touched through the text editor.

    A page template looks something like this:

    <?php
    /*
    Template Name: Generic Template
    */
    ?>
    <?php get_header(); ?>
    	<div id="posts-column">
    	<div class="borderlayer">
    		<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    		<div class="post" id="post-<?php the_ID(); ?>">
    			<h2><?php the_title(); ?></h2>
    			<?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
    			<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    		</div>
    		<?php endwhile; endif; ?>
    	<?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
    	</div>
    	</div>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    get_header, have_posts, the_title, etc are all functions of WordPress. From <?php if (have_posts()) : while (have_posts()) : the_post(); ?> to <?php endwhile; endif; ?> is called “The Loop”. Everything there is directly related to the content a user can edit. <?php the_title(); ?> is the title of the page and <?php the_content(); ?> is the content of the page (obviously). You can move them around within the loop to be displayed however you want them to be displayed. Outside of the loop you can add any other content you want, like the iframe.

    I know it’s kind of confusing and I’m not sure I do it any justice, but once you try it out you’ll get what I mean and see that its exactly what you’re looking for. You don’t really have to know php to work with it.

    Thread Starter pommie

    (@pommie)

    @jdb – Many thanks for taking the trouble to go into that detail – it’s enough to get me to delve in there and give it a go so it’s much appreciated!!!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘WordPress ate my HTML code’ is closed to new replies.