WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] How can I enable WYSIWYG view for custom fields

[Resolved] How can I enable WYSIWYG view for custom fields

  • I usually use html view exclusively but I need the custom fields to work in WYSYWIG mode. Because I use custom fields to post references in the form of urls and since custom fields seem to work just in html mode the urls are not transformed into hyperlinks. I don’t feel like going through each url and adding <a href… to them one by one. How can I make custom fields work in WYSYWYG mode?

    P.S. changing tinymce’s mode from html to “view” doesn’t do it either 🙁

Viewing 15 replies - 1 through 15 (of 16 total)
  • In other words: How do your auto hyperlink URLS posted via custom fields?

    esmi

    @esmi

    Forum Moderator

    Add the link markup via the template when you display the custom field(s).

    You can use the Custom Field Templates plugin and create a field with TinyMCE (WYSIWYG editor WordPress uses).

    Sorry guys but the Custom Field Template plugin isn’t doing it. It’s helpful in other ways but for whatever reason it doesn’t auto-hyperlink urls.

    I tried using another plugin that does do that but it works only on post and comment content (doesn’t auto-link custom field urls).

    As Esmi said..

    Add the link markup via the template when you display the custom field(s).

    Like so…

    <?php $yourfield = get_post_meta($post->ID,'yourfieldname',true);
    if($yourfield) echo '<a href="'.$yourfield.'">'.$yourfield.'</a>'
    ?>

    There’s a number of ways, that’s just one..

    You’d add that to whichever file is handling the given page you are viewing, examples would be index.php, single.php, page.php (you get the point).

    Thanks guys, I admit I wasn’t sure as to what esmi had meant earlier.

    t31os_: before I had two consecutive text urls like this:

    <p>http://google.com</p&gt;
    <p>http://yahoo.com</p&gt;

    after employing your code it now looks like this:

    http://google.com</p&gt;
    <p>http://yahoo.com</p&gt;
    “><p>http://google.com</p&gt;
    <p>http://yahoo.com</p&gt;

    As you can see the paragraph tags are causing problems (which I didn’t put in the first place but wordpress did automatically). Aside from that the two consecutive links have become one i.e. they are both within the same link tag. Is there any way to fix this (sorry, php is something I’m still struggling with).

    Thanks

    there was an:

    before the http://goo

    dammit wordpress keeps hyperlinks the code :p

    esmi

    @esmi

    Forum Moderator

    Use backticks to enclose code or markup. Sorry I was so brief earlier. I was being called away.

    I’m confused as to why WP is adding paragraph tags. As far as I was aware, get_post_meta doesn’t go through any formatting filters. Does:

    <?php $yourfield = get_post_meta($post->ID,'yourfieldname',true);
    if($yourfield) echo '<a href="'.$yourfield.'">'.strip_tags($yourfield).'</a>'
    ?>

    help?

    What is the value of this field (take any one you have as an example), are you storing multiple url’s in the 1 field?

    Thank you esmi, it was the Custom field template plugin’s TinyMce editor that was adding the pagaraph tags. I deactivated it now and am using the default custom fields. The code you posted does work but only for single urls. If I post two textually like this:

    http://google.com<br />
    http://yahoo.com

    it is turned in into this:

    <a href="http://people.com%0A%3Cbr/%3E%0Ahttp://google.com">http://people.com%0A%3Cbr/%3E%0Ahttp://google.com</a>

    again they are both inside the same link tag…

    t31os_: the value is called website and you just reminded me, I am using the same field for multiple urls. I will try using different fields and see how it goes…

    Apparently posting the urls one at a time in the custom fields only makes the first one appear and not the rest…

    esmi

    @esmi

    Forum Moderator

    You need to enter each url separately – though you could call each field “website” and have 2 or more per post. Then you’d need something like:

    <?php $yourfield = get_post_meta($post->ID,'website',false);
    if(count($yourfield) <0) {
    	foreach($yourfield as $this_one) {
    		echo '<a href="'.$this_one.'">'.$this_one.'</a>'
    	}
    }
    ?>

    esmi that code gives me a parse error, I guess I can just rename the custom fields to website1, website2 and so on and call them using the earlier code.

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘[Resolved] How can I enable WYSIWYG view for custom fields’ is closed to new replies.
Skip to toolbar