Characters being replaced by bbcode plugin - php

I have a bbcode plugin for wordpress.
But for some reason, if I post something like
[i]v497212he2x2MfMi[/i] the "X" character is outputted as ×, which is some other sort of X. How can I fix this?
Plugin code is below:
class BBCode {
// Plugin initialization
function BBCode() {
// This version only supports WP 2.5+ (learn to upgrade please!)
if ( !function_exists('add_shortcode') ) return;
// Register the shortcodes
add_shortcode( 'b' , array(&$this, 'shortcode_bold') );
add_shortcode( 'i' , array(&$this, 'shortcode_italics') );
}
// No-name attribute fixing
function attributefix( $atts = array() ) {
if ( empty($atts[0]) ) return $atts;
if ( 0 !== preg_match( '#=("|\')(.*?)("|\')#', $atts[0], $match ) )
$atts[0] = $match[2];
return $atts;
}
// Bold shortcode
function shortcode_bold( $atts = array(), $content = NULL ) {
if ( NULL === $content ) return '';
return '<strong>' . do_shortcode( $content ) . '</strong>';
}
// Italics shortcode
function shortcode_italics( $atts = array(), $content = NULL ) {
if ( NULL === $content ) return '';
return '<em>' . do_shortcode( $content ) . '</em>';
}
}
// Start this plugin once all other plugins are fully loaded
add_action( 'plugins_loaded', create_function( '', 'global $BBCode; $BBCode = new BBCode();' ) );

This transformation is taking place because of Wordpress's wptexturize() function that returns given text with transformations of quotes to smart quotes, apostrophes, dashes, ellipses, the trademark symbol, and the multiplication symbol.
This is from WP 3.2.1 wp-includes/formatting.php line 55:
$dynamic_characters = array('/\'(\d\d(?:’|\')?s)/', '/\'(\d)/', '/(\s|\A|[([{<]|")\'/', '/(\d)"/', '/(\d)\'/', '/(\S)\'([^\'\s])/', '/(\s|\A|[([{<])"(?!\s)/', '/"(\s|\S|\Z)/', '/\'([\s.]|\Z)/', '/\b(\d+)x(\d+)\b/');
$dynamic_replacements = array('’$1','’$1', '$1‘', '$1″', '$1′', '$1’$2', '$1' . $opening_quote . '$2', $closing_quote . '$1', '’$1', '$1×$2');
The last regex in that $dynamic_characters array is the one turning the "X" into ×
As stated on the function page for wptexturize... "[t]ext enclosed in the tags <pre>, <code>, <kbd>, <style>, <script>, <tt>, and [code] will be skipped.", you can fix this by putting that bbcode in one of those tags, or use a plugin that can disable wptexturize, such as InScript or Disabler or Disable wptexturize.

Related

Wordpress Invalid Range In Character Class After Update

I have a problem about Visual Compser Backend not showing any elements, it only shows the code in the classic mode editor.
See Screenshot
Warning: preg_match_all(): Compilation failed: invalid range in character class at offset 11 in /home/customer/www/******.com/public_html/wp-content/plugins/js_composer/include/autoload/hook-vc-grid.php on line 162
This is line 162
preg_match_all( "/$pattern/", $post->post_content, $found ); // fetch only needed shortcodes
```public function gridSavePostSettingsId( array $settings, $post_id, $post ) {
$pattern = $this->getShortcodeRegexForId();
preg_match_all( "/$pattern/", $post->post_content, $found ); // fetch only needed shortcodes
$settings['vc_grid_id'] = array();
if ( is_array( $found ) && ! empty( $found[0] ) ) {
$to_save = array();
if ( isset( $found[1] ) && is_array( $found[1] ) ) {
foreach ( $found[1] as $key => $parse_able ) {
if ( empty( $parse_able ) || '[' !== $parse_able ) {
$id_pattern = '/' . $this->grid_id_unique_name . '\:([\w-_]+)/';
$id_value = $found[4][ $key ];
preg_match( $id_pattern, $id_value, $id_matches );
if ( ! empty( $id_matches ) ) {
$id_to_save = $id_matches[1];
// why we need to check if shortcode is parse able?
// 1: if it is escaped it must not be displayed (parsed)
// 2: so if 1 is true it must not be saved in database meta
$shortcode_tag = $found[2][ $key ];
$shortcode_atts_string = $found[3][ $key ];
/** #var $atts array */
$atts = shortcode_parse_atts( $shortcode_atts_string );
$content = $found[6][ $key ];
$data = array(
'tag' => $shortcode_tag,
'atts' => $atts,
'content' => $content,
);
$to_save[ $id_to_save ] = $data;
}
}
}
}
if ( ! empty( $to_save ) ) {
$settings['vc_grid_id'] = array( 'shortcodes' => $to_save );
}
}
return $settings;
}```
I tried disabling all plug-ins and rollback wordpress version but still the same.
Is this problem related to the warning above? I know very little about coding. Please point me in the right direction.
Thank you!
Exactly same problem back-end mode didn't show any elements and /hook-vc-grid.php on line 162 error. " [\w-_] is wrong, it must be [\w-] " this helps only dissappear error but not solution for not showing elements.
Edit: php 7.1 works. It solved elements thing also.
Thank you guys
All hyphen '-' characters (that are not used as a range character) should be escaped '\-' as of PHP 7.3 so that it will NOT be treated anymore as a range character. Therefor the following WordPress function needs to be changed this way to make this expression work the same again:
private function getShortcodeRegexForId() {
return '\\[' // Opening bracket
. '(\\[?)' // 1: Optional second opening bracket for escaping shortcodes: [[tag]]
. '([\\w\-_]+)' // 2: Shortcode name
. '(?![\\w\-])' // Not followed by word character or hyphen

Strip automatic P tags around images, videos, iframes in WordPress 4.9

THE ISSUE
I'm trying to size my YouTube video that I'm inserting and I got some working CSS to style it correctly, but the fact that WordPress keeps adding <P> tags around my video, image, and iframe tags is breaking my code. I'm only trying to remove paragraph tag wraps from elements (video/img/iframe) in blog content sections (not sidebars, widgets, footers, etc.)
CLIENT WEBSITE:
This website is for a client so the code needs to be as unobtrusive as possible. For instance, a good solution would be a custom shortcode, or something that allows me to target the videos with CSS styling rules.
Here is a blog post on the website in question:
http://ehepperle.com/in-progress/feelheal/11/how-to-create-125-px-ad-banner-gimp/
MY SYSTEM
WordPress: 4.9.6
Theme: Storefront
Website: http://ehepperle.com/in-progress/feelheal/11/how-to-create-125-px-ad-banner-gimp/
MY CODE
Since this is specific to WordPress filters rather than general coding concepts, I haven't found a way to make a good demonstration example, but here are code snippets showing what I've tried:
functions.php - ver. 1
// Remove P Tags Around Images
// From: http://justlearnwp.com/remove-p-tag-around-wordpress-images/
function filter_ptags_on_images($content){
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
}
add_filter('the_content', 'filter_ptags_on_images');
functions.php - ver. 2
// https://stackoverflow.com/questions/44539888/remove-automatic-p-tag-in-wordpress#answer-44540531
function reformat_auto_p_tags($content) {
$new_content = '';
$pattern_full = '{(\[raw\].*?\[/raw\])}is';
$pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
$pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);
foreach ($pieces as $piece) {
if (preg_match($pattern_contents, $piece, $matches)) {
$new_content .= $matches[1];
} else {
$new_content .= wptexturize(wpautop($piece));
}
}
return $new_content;
}
remove_filter('the_content', 'wpautop');
remove_filter('the_content', 'wptexturize');
add_filter('the_content', 'reformat_auto_p_tags', 99);
add_filter('widget_text', 'reformat_auto_p_tags', 99);
LINKS I REVIEWED BEFORE POSTING
I've tried solutions pieced together from these different possible solutions, all to no avail.
From: Remove automatic p tag in WordPress
http://justlearnwp.com/remove-p-tag-around-wordpress-images/
How to Remove P Tags Around Images in WordPress Posts From Source Code
https://www.daddydesign.com/wordpress/how-to-remove-the-paragraph-tag-from-images-inside-the-wordpress-post-content/
https://ahmadawais.com/remove-the-p-paragraph-tags-from-author-description-in-wordpress/
https://firstsiteguide.com/stop-adding-paragraphs-automatically/#comment-424246
https://codex.wordpress.org/Function_Reference/wpautop
http://micahjon.com/2016/removing-wrapping-p-paragraph-tags-around-images-wordpress/
How to remove p tag from wordpress
MY QUESTIONS
The following questions are actually multiple aspects of the same main question to gather the most complete understanding from various perspectives.
How can I remove <p> tags from iframes, video, and image tags in WordPress? The methods I've located from the past 2 years (and earlier) don't seem to work.
What is wrong with my code? Why are removing wpautop filters not working in my functions.php?
Did something change with WP version 4.8-4.9 that is making these filter hacks not work any more?
UPDATE: 2018-09-05
I'm adding my complete functions.php file in case anyone can help identify something that is causing a conflict. I don't see any, but maybe you will see something I missed.
functions.php (complete)
<?php
add_action( 'wp_enqueue_scripts', function() {
//* Parent CSS
wp_enqueue_style( 'storefront',
get_template_directory_uri() . '/style.css' );
//* Child CSS
wp_enqueue_style( 'storefront-ehw-1',
get_stylesheet_directory_uri() . '/style.css', [ 'storefront' ] );
} );
/* Adds search box to top nav menu
add_filter( 'wp_nav_menu_items','add_search_box', 10, 2 );
function add_search_box( $items, $args ) {
$items .= '<li class="widget widget_search">' . get_search_form( false ) . '</li>';
return $items;
}
*/
/* Hide categories from WordPress category widget
NOTE: 59 is the id of .Test-Posts category. This hides that from users.*/
function exclude_widget_categories($args){
$exclude = "59";
$args["exclude"] = $exclude;
return $args;
}
add_filter("widget_categories_args","exclude_widget_categories");
/* Add Google fonts */
function wpb_add_google_fonts() {
wp_enqueue_style( 'wpb-google-fonts', 'http://fonts.googleapis.com/css?family=Aguafina Script|Neucha|The Girl Next Door|Quintessential|Open Sans|Raleway', false );
}
add_action( 'wp_enqueue_scripts', 'wpb_add_google_fonts' );
/**
* Display the theme credit
*
* #since 1.0.0
* #return void
*/
function storefront_credit() {
?>
<div class="site-info">
<?php echo esc_html( apply_filters( 'storefront_copyright_text', $content = 'Copyright © ' . date( 'Y' ) . ' ' . get_bloginfo( 'name' ) ) ); ?>
<?php if ( apply_filters( 'storefront_credit_link', true ) ) { ?>
<br />
<?php echo '' . esc_html__( 'Designed by: Eric Hepperle Designs', 'storefront-ehw-1' ) . '' ?>
<?php } ?>
</div><!-- .site-info -->/*<?php
}
/* **** VARIOUS ATTEMPTS TO REMOVE P-TAGS FROM YOUTUBE VIDEO THUMBNAILS ****
// Remove P Tags Around Images
// From: http://justlearnwp.com/remove-p-tag-around-wordpress-images/
function filter_ptags_on_images($content){
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
}
add_filter('the_content', 'filter_ptags_on_images');
// Remove P Tags Around videos
function filter_ptags_on_vids($content){
return preg_replace('/<video>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/video>/iU', '\1\2\3', $content);
}
add_filter('the_content', 'filter_ptags_on_vids');
// https://stackoverflow.com/questions/44539888/remove-automatic-p-tag-in-wordpress#answer-44540531
function reformat_auto_p_tags($content) {
$new_content = '';
$pattern_full = '{(\[raw\].*?\[/raw\])}is';
$pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
$pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);
foreach ($pieces as $piece) {
if (preg_match($pattern_contents, $piece, $matches)) {
$new_content .= $matches[1];
} else {
$new_content .= wptexturize(wpautop($piece));
}
}
return $new_content;
}
remove_filter('the_content', 'wpautop');
remove_filter('the_content', 'wptexturize');
add_filter('the_content', 'reformat_auto_p_tags', 99);
add_filter('widget_text', 'reformat_auto_p_tags', 99);
// ------------ FROM STACK OVERFLOW ------------------------
//
// Remove p tags from images, scripts, and iframes.
function remove_some_ptags( $content ) {
$content = preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
$content = preg_replace('/<p>\s*(<script.*>*.<\/script>)\s*<\/p>/iU', '\1', $content);
$content = preg_replace('/<p>\s*(<iframe.*>*.<\/iframe>)\s*<\/p>/iU', '\1', $content);
return $content;
}
add_filter( 'the_content', 'remove_some_ptags' );
*/
// Add the filter to manage the p tags
add_filter( 'the_content', 'jb_remove_autop_for_image', 0 );
function jb_remove_autop_for_image( $content )
{
global $post;
// Here you can write condition as per your requirement.
// i have added example for your idea
if ( is_single() && $post->post_type == 'image' )
remove_filter('the_content', 'wpautop');
return $content;
}
Please try below code.
// Add the filter to manage the p tags
add_filter( 'the_content', 'jb_remove_autop_for_image', 0 );
function jb_remove_autop_for_image( $content )
{
global $post;
// Here you can write condition as per your requirement.
// i have added example for your idea
if ( is_single() && $post->post_type == 'image' )
remove_filter('the_content', 'wpautop');
return $content;
}
You can wrap embedded iframes, images, videos etc. in your own wrapper. WP then wouldn't add <p> tags. Use 'oembed_dataparse' filter.
// Wrap iframe for embedded video in <div> with custom class.
// Add class-modifier if aspect ratio is 4/3.
function wrap_oembed_dataparse($return, $data, $url) {
$mod = '';
if ( ( $data->type == 'video' ) &&
( isset($data->width) ) && ( isset($data->height) ) &&
( round($data->height/$data->width, 2) == round( 3/4, 2) )
)
{
$mod = 'embed-responsive--4-3';
}
return '<div class="embed-responsive ' . $mod . '">' . $return . '</div>';
}
add_filter( 'oembed_dataparse', 'wrap_oembed_dataparse', 99, 4 );
This Vanilla-JS-function searches for all iframes, and moves them outside of their parents:
moveIframesOutOfPtags() {
let iframes = document.querySelectorAll( 'iframe' );
let before = "<div class="iframe-container">";
let after = "</div>";
Object.entries( iframes ).forEach( entry => {
let value = entry[1];
if( value.parentNode.nodeName === 'P' || value.parentNode.nodeName === 'p' ){
value.parentNode.outerHTML = before + value.parentNode.innerHTML + after;
}
});
}
Tested and works.
I'm using it in a Vue-app, so I've put it in the mounted section. If you're not using vue, then you would have to put the function inside a <script and run it inside some window.onload(() => { ... });
Depending on how you control the scripts on your page, then you should put it there, enqueued in your functions-file (good) or just straight up in the footer (bad).
Bonus info
I've also added a container-div (.iframe-container) to put the iframe into. By using this method then you can add these styles and then scale the iframe to fill 100% width, an keeping a set aspect ratio%.
Here I am sending the code for removing p tag From Images scripts and iframes.
// Remove p tags from images, scripts, and iframes.
function remove_some_ptags( $content ) {
$content = preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
$content = preg_replace('/<p>\s*(<script.*>*.<\/script>)\s*<\/p>/iU', '\1', $content);
$content = preg_replace('/<p>\s*(<iframe.*>*.<\/iframe>)\s*<\/p>/iU', '\1', $content);
return $content;
}
add_filter( 'the_content', 'remove_some_ptags' );
Kindly check.

Wordpress | Apply function/filter to specific template (featured image function filter)

I have the following code in my tweaks plugin.
add_filter( 'the_content', 'sqhse_news_featimgmove', 20 );
function sqhse_news_featimgmove( $content ) {
$content = preg_replace( "/<\/p>/", "</p>" . get_the_post_thumbnail($post->ID,'post-single', array( 'class' => "img-fluid img-rounded w-100")) . "<div class='clearfix' style='margin-bottom:10px;'></div>", $content, 1 );
return $content;
}
What it does:
It adds the featured image after the first paragraph which is great and exactly what I need.
The problem: The code applies itself to single.php (great that's where I need it) but it also applies itself to single-training_courses.php (a template for a custom post type).
The help required: Apply the code to single.php and not any sub single templates such as single-training_courses.php
Is this achievable? and if so how may I achieve this?
You can use get_post_type() WordPress function and wrap your code inside an if statement as follow:
add_filter( 'the_content', 'sqhse_news_featimgmove', 20 );
function sqhse_news_featimgmove( $content ) {
if( get_post_type() == 'post' ) {
$content = preg_replace( "/<\/p>/", "</p>" . get_the_post_thumbnail($post->ID,'post-single', array( 'class' => "img-fluid img-rounded w-100")) . "<div class='clearfix' style='margin-bottom:10px;'></div>", $content, 1 );
return $content;
}
return $content;
}
The filter you're using, the_content, as you've discovered will apply to all content areas. You need to add a conditional to check the post type you're on and adjust accordingly. My suggestion would be to use is_singular().
add_filter( 'the_content', 'sqhse_news_featimgmove', 20 );
function sqhse_news_featimgmove( $content ) {
if ( is_singular( 'post' ) ) {
$content = preg_replace( "/<\/p>/", "</p>" . get_the_post_thumbnail($post->ID,'post-single', array( 'class' => "img-fluid img-rounded w-100")) . "<div class='clearfix' style='margin-bottom:10px;'></div>", $content, 1 );
}
return $content;
}
When dealing with filters make sure you always return a value. If you have a conditional for example keep the return statement outside of it.
https://codex.wordpress.org/Function_Reference/is_singular

How to strip all visual composer shortcode/tags from wordpress's post_content fetched with custom query

I am working on a web-service(API) where i am fetching result WP_query() function and parse that in JSON format. which will further use in android application.
The problem is the post_content i am getting with query is composed by visual composer and the whole content is in form of such tags like
[VC_ROW][/VC_ROW][VC_COLUMN]some text[/VC_COLUMN] etc.
I want to remove/strip all these shortcode from the content and retrieve only plain text from it. Is there any visual composer function through which i can achieve this thing
<?php
require('../../../wp-load.php');
require_once(ABSPATH . 'wp-includes/functions.php');
require_once(ABSPATH . 'wp-includes/shortcodes.php');
header('Content-Type: application/json');
$post_name = $_REQUEST['page'];
if($post_name!=''){
if($post_name=='services') {
$args = array(
'post_parent' => $page['services']['id'],
'post_type' => 'page',
'post_status' => 'published'
);
$posts = get_children($args);
foreach($posts as $po){
$services_array[] = array('id'=>$po->ID,'title'=>$po->post_title,'image'=>get_post_meta($po->ID, 'webservice_page_image',true),'description'=>preg_replace("~(?:\[/?)[^/\]]+/?\]~s", '', $po->post_content));
}
$post = array(
'status'=>'ok',
'services'=>$services_array
);
echo json_encode($post);
}
}
?>
I want to remove/strip all these shortcode from the content and retrieve only plain text from it.
Solution that worked for me:
$content = strip_tags( do_shortcode( $post->post_content ) );
do_shortcode triggers all visual composer shortcodes and thus returns html+text;
strip_tags removes all html tags and returns plain text.
Here, you can try and easily add some short codes in array that you needs and also you can remove all shortcodes via below code.
$the_content = '[VC_ROW][VC_COLUMN]some text1[/VC_COLUMN] etc.[/VC_ROW][VC_COLUMN_INNTER width="1/3"][/VC_COLUMN_INNTER]';
$shortcode_tags = array('VC_COLUMN_INNTER');
$values = array_values( $shortcode_tags );
$exclude_codes = implode( '|', $values );
// strip all shortcodes but keep content
// $the_content = preg_replace("~(?:\[/?)[^/\]]+/?\]~s", '', $the_content);
// strip all shortcodes except $exclude_codes and keep all content
$the_content = preg_replace( "~(?:\[/?)(?!(?:$exclude_codes))[^/\]]+/?\]~s", '', $the_content );
echo $the_content;
you want to remain some shortcodes you can't use strip_shortcodes() for that.
Best solution, solved.
Just add the following code to file wp-includes/rest-api.php, at the bottom:
/**
* Modify REST API content for pages to force
* shortcodes to render since Visual Composer does not
* do this
*/
add_action( 'rest_api_init', function ()
{
register_rest_field(
'page',
'content',
array(
'get_callback' => 'compasshb_do_shortcodes',
'update_callback' => null,
'schema' => null,
)
);
});
function compasshb_do_shortcodes( $object, $field_name, $request )
{
WPBMap::addAllMappedShortcodes(); // This does all the work
global $post;
$post = get_post ($object['id']);
$output['rendered'] = apply_filters( 'the_content', $post->post_content );
return $output;
}
I took it somewhere and update it a bit, to work a bit better :).
in functions.php add this function:
/** Function that cuts post excerpt to the number of a word based on previously set global * variable $word_count, which is defined below */
if(!function_exists('kc_excerpt')) {
function kc_excerpt($excerpt_length = 20) {
global $word_count, $post;
$word_count = $excerpt_length;
$post_excerpt = get_the_excerpt($post) != "" ? get_the_excerpt($post) : strip_tags(do_shortcode(get_the_content($post)));
$clean_excerpt = strpos($post_excerpt, '...') ? strstr($post_excerpt, '...', true) : $post_excerpt;
/** add by PR */
$clean_excerpt = strip_shortcodes(remove_vc_from_excerpt($clean_excerpt));
/** end PR mod */
$excerpt_word_array = explode (' ',$clean_excerpt);
$excerpt_word_array = array_slice ($excerpt_word_array, 0, $word_count);
$excerpt = implode (' ', $excerpt_word_array).'...'; echo ''.$excerpt.'';
}
}
and after that you call it normally kc_excerpt(20); and it will return normal post_content/excerpt
How to remove visual composer from wp post: i.e [vc_row][vc_column width=\"2/3\"][distance][vc_single_image image=\"40530\" img_size=\"large\"][distance][distance][distance][vc_column_text]
Also WP post remvoe short codes and html tags.
while($posts->have_posts()) {
$postContent = get_the_content();
//Remove html tags. and short code
$postContent = strip_tags( do_shortcode( $postContent ) );
//Remove visual composer tags [vc_column] etc
$postContent = preg_replace( "/\[(\/*)?vc_(.*?)\]/", '', $postContent );
}
Looking source code from wordpress api, I did a function to remove some shortcode from content. So this is the result:
function removeShortcode($content, $shortcodeList){
preg_match_all('#\[([^<>&/\[\]\x00-\x20=]++)#', $content, $matches);
$tagnames = array_intersect($shortcodeList, $matches[1]);
if(empty($tagnames)){
return $content;
}
$pattern = get_shortcode_regex($tagnames);
preg_match_all("/$pattern/", $content, $matchesTags);
foreach ($matchesTags[0] as $key => $value) {
$content = str_replace($value, $matchesTags[5][$key], $content);
}
return $content;
}
example:
$content = "<p>Hi, this is a [example]<b>example</b>[/example]. [end]</p>";
$shortcodesToRemove = ["example", "end"];
echo removeShortcode($content, $shortcodesToRemove);
foreach($posts as $po){
$services_array[] = array('id'=>$po->ID,'title'=>$po->post_title, 'description'=>do_shortcode($po->post_content));
}
You should try this.

Best way to use functions.php to filter ACF in Wordpress

I'm currently pulling in multiple pieces of content into my posts through an AFC with the value: "section_content". Furthermore, I'm using the code below to clean up my WP posts. How would I modify this filter to also include my ACF?
<?php
/**
* Clean posts from inline styling and unnecessary tags
*/
add_filter( 'the_content', 'clean_post_content' );
function clean_post_content($content) {
if ( is_single() ) {
$patterns = array(
'/(<[^>]+) style=".*?"/i', // Remove inline styling
'/<\/?font[^>]*>/', // Remove font tag
'/<(p|span)>(?>\s+| |(?R))*<\/\1>/', // Empty p, span (font tags already removed)
'/(<h[1-6]>[^<]*)<\/?strong>(.*?<\/h[1-6]>)/', // h1-6
);
$replacements = array(
'$1',
'',
'',
'$1$2'
);
$old_content = '';
while ($old_content != $content) {
$old_content = $content;
$content = preg_replace($patterns, $replacements, $content);
}
}
return $content;
}
?>
I guess you could use ACF Filters. I usually hook to acf/format_value in order to clean or modify my custom field values before printing them.
You can even hook to certain field types only, like:
function acf_brand_trademark( $value, $post_id, $field ) {
$value = preg_replace( '/Brand /', 'Brand<sup>™</sup> ', $value );
return $value;
}
add_filter('acf/format_value/type=textarea', 'acf_brand_trademark', 10, 3);
add_filter('acf/format_value/type=text', 'acf_brand_trademark', 10, 3);
Hope this helps!

Categories