Support

Account

Home Forums General Issues Remove/filter WSIWYG output – remove HTML tags

Solved

Remove/filter WSIWYG output – remove HTML tags

  • Hi,

    I’ve just started using ACF and really impressed with it so far, one of the most intuitive plugins I worked with! 🙂

    I have a client who wants a scrolling news text box on their homepage which is using the home.php template. To do this I’ve created a private post that just has a basic WYSIWYG in and picked it up in the home.php file and it works fine. I’ve done it like this so that they can easily add links using the link icon rather than having to paste html into a widget etc.

    However, at the moment if I add line breaks or other markup it shows up the designated <div>. I know I can fix the height of the div but is it possible to:

    – remove all icons from basic editor box except the link ones
    – filter / remove all markup except href links (e.g. remove and <h1>, <br> etc etc?

    Finally as far as I can tell using a Private post works fine and content still comes through via ACF so I guess this is acceptable to use?

    Regards

    Andrew

  • Firstly sorry for the rather unclear title – not sure I have the option to edit it?

    I found this with some more searching – http://us3.php.net/strip_tags – which might be an option but I’m kinda hoping there’s a simpler solution around ACF?

    Thanks

    Andrew

  • Hi @Andrew C

    Thanks for the question.

    = Custom WYSIWYG toolbar buttons =
    Yes, please read this article to create a custom set of buttons (only link)
    http://www.advancedcustomfields.com/resources/tutorials/customize-the-wysiwyg-toolbars/

    = filter / remove markup =
    ACF does not contain a function for this, but I’m sure WP or PHP (please search on google) has a function!

    = private posts =
    Yes, ACF works with private posts just fine

    Thanks
    E

  • Thanks Elliot that’s great, I’ll have a play around with that and have a look at using the PHP function in the link to recheck the output.

    Andrew

  • Hi Elliot,

    Sorry for being a total newbie here but I made a straight copy of the code from the link in your reply and pasted it into functions.php in my child theme. The code did as the comments said but I can’t update any posts etc now and am getting errors when I try to update the ACF group or save any post.

    Screenshot of error below:

    Error screenshot

    Thanks

    Andrew

  • Try again with screenshot

  • Hi @Andrew C

    Your error states that on line 35 of your functions.php file you are outputting some HTML.

    What is the code on line 35? and what is the entire function that it sits in?

    Thanks
    E

  • Hi Elliot,

    I’ve just copied the code from you example as below – but the strange thing is that there isn’t any code on line 35 – the file ends on line 33 … I created the functions.php file just for this so it’s the only thing in it?

    Is it because I’ve closed the php tag at the end – I’m sure I read somewhere it can cause problems?

    Entire code of functions.php

    <?php
     
    add_filter( 'acf/fields/wysiwyg/toolbars' , 'my_toolbars'  );
    function my_toolbars( $toolbars )
    {
    	// Uncomment to view format of $toolbars
    	/*
    	echo '< pre >';
    		print_r($toolbars);
    	echo '< /pre >';
    	die;
    	*/
     
    	// Add a new toolbar called "Very Simple"
    	// - this toolbar has only 1 row of buttons
    	$toolbars['Very Simple' ] = array();
    	$toolbars['Very Simple' ][1] = array('bold' , 'italic' , 'underline' );
     
    	// Edit the "Full" toolbar and remove 'code'
    	// - delet from array code from http://stackoverflow.com/questions/7225070/php-array-delete-by-value-not-key
    	if( ($key = array_search('code' , $toolbars['Full' ][2])) !== false )
    	{
    	    unset( $toolbars['Full' ][2][$key] );
    	}
     
    	// remove the 'Basic' toolbar completely
    	//unset( $toolbars['Basic' ] );
     
    	// return $toolbars - IMPORTANT!
    	return $toolbars;
    }
     
    ?>
  • Hi @Andrew C

    If you remove all code from the functions.php file does the error go away?

    If you change the function to this, does the error go away?

    
    function my_toolbars( $toolbars )
    {
    	// return $toolbars - IMPORTANT!
    	return $toolbars;
    }
    
  • Hi Elliot,

    I’ve just been experimenting with the code and if I remove the closing ?> on the final line it all seems to work fine.

    I can check the above if you want – I presume I would wrap that in <?php … ?> though?

    Thanks

    Andrew

  • Just checked the code and if I have

    <?php
    
    function my_toolbars( $toolbars )
    {
    	// return $toolbars - IMPORTANT!
    	return $toolbars;
    }
    
    ?>

    I get the same error messages, however,

    <?php
    
    function my_toolbars( $toolbars )
    {
    	// return $toolbars - IMPORTANT!
    	return $toolbars;
    }

    Then it works fine as does the original paste from the explanation page… so that seems to have sorted it…?

  • Hi @Andrew C

    Perhaps this is a server setting which does not like closing PHP tags?

    Thanks
    E

  • Hi Elliot,

    I did some digging around to try and find where I had read that and came up with these 2

    http://hardcorewp.com/2013/always-omit-closing-php-tags-in-wordpress-plugins/
    http://wordpress.org/support/topic/functionsphp-in-a-child-theme

    I think in my case having read the WP.org one and the error saying it was on line 35 when my functions.php only went to line 33 this probably surmises by problem:

    The Codex isn’t wrong. There should be closing PHP tag at the end of the file. Furthermore, that closing tag has to be the very last line of the file. If you have any blank lines after the closing tag, that can break things, too.

    There isn’t any visible text after the closing tag but it appears it might not have been the last line…

    Will check that tonight and try putting the closing tag back in.

    Thanks

    Andrew

Viewing 13 posts - 1 through 13 (of 13 total)

The topic ‘Remove/filter WSIWYG output – remove HTML tags’ is closed to new replies.