WordPress.org

Ready to get started?Download WordPress

Forums

how do you stop visual editor from striping or changing ">" php code (5 posts)

  1. barbaricht
    Member
    Posted 1 year ago #

    If i enter this code
    <?php echo site_url(); ?>

    in the HTML editor and switch to visual editor the php characters < > are replaced by HTML character entities, which renders the code useless.

    I need to have both editors available.

    thank you,
    -tony

  2. ClaytonJames
    Member
    Posted 1 year ago #

    'Yep. flipping between editors will often change code you entered in HTML mode.

    Also, you probably cannot enter php code in the visual editor and expect it to run, as a general rule of thumb. Generally speaking,I don't think PHP code will run by default from a post or a page when entered from the visual or the HTML editor (if that's your goal).

    Perhaps you need a plugin that will allow you to run php from a post or page? Or are you just trying to post code snippets for display in an article?

    A general search: http://wordpress.org/extend/plugins/search.php?q=php+in+post+page&sort=

  3. barbaricht
    Member
    Posted 1 year ago #

    Dear James,

    Thank you for your response. My goal was not hardcode absolute URL's for image tags. As a result, I added image tags in this way below using the HTML editor:
    <img src="<?php echo site_url(); ?>/wp-content/uploads/2012/11/newsletter.png" />

    I did this because i will be uploading a local/development wordpress website to production on the Interent using a different domain name.

    This method worked fine, until i switch to the visual editor, which change the php code as described in the above posts.

    And yes i'm using a plugin that allow me to add php code in the HTML editor. The name of plug-in is "PHP Code for posts".

    thank you!

  4. bcworkz
    Member
    Posted 1 year ago #

    A few random thoughts for possible workarounds...
    1. Will the php code plugin still work if you used < and > to denote code blocks?
    2. Consider creating a shortcode to insert the site url.
    3. Develop the discipline to only work in html. Use the post preview feature to view the results.

    Cheers!

  5. barbaricht
    Member
    Posted 1 year ago #

    Dear bcworkz,

    thank you for you comments! To answer your questions starting with the first: the php code won't work with code blocks. The visual editor still changes < > to character entities even though they are wrapped in code blocks.

    The short code idea i like. I don't know anything about short code because i just starting learning wordpress a month ago. So i take a look at it.

    lastly, i'm a web developer by profession and i use many programming languages. I could never only use html.

    -tony

Topic Closed

This topic has been closed to new replies.

About this Topic