Consider a custom MediaWiki extension that adds a new tag named simplified_example with some JavaScript (just calling alert with provided argument for simplicity):
<?php
if ( ! defined( 'MEDIAWIKI' ) ) die();
$wgExtensionFunctions[] = 'registerTags';
$wgExtensionCredits['parserhook'][] = array(
'name' => 'myTags',
);
function registerTags() {
global $wgParser;
$wgParser->setHook('simplified_example', function ($input, $argv, $parser, $frame) {
$output = $parser->recursiveTagParse($input, $frame);
$title = $argv["value"];
return "<div onclick=\"alert('$title')\">$output</div>";
});
}
?>
Using that I can put following code in a MediaWiki page source:
<simplified_example value="Testing">...</simplified_example>
This results with ... div being clickable - a message box with provided text is displayed. Now I wanted to place this tag inside a template, like this:
<simplified_example value="{{{1}}}">...</simplified_example>
When I put this template into a MediaWiki page:
{{TestTemplate|Testing...}}
Once again I obtain a clickable ... but displayed message is not evaluated and {{{1}}} is displayed instead of provided Testing....
How can I pass the argument from MediaWiki page source down to my custom tag through a template?
Try to use #tag function instead of html in your template, like this:
{{#tag:simplified_example|value={{{1}}} }}
I'm using ACF together with the ACF Hook acf/load_value to add a custom HTML wrapper to the ACF value. I use then the ACFs to build an Elementor template (I'm using Elementor PRO).
The Template works and the values of ACFs are rendered, but the attribute I've added in the wrapper disappear
I've tried to change the priority of my filters, but it wasn't the problem. I 've also tried to look into the ACF settings, but seems that I cannot change this behavior just changing some settings.
This is the filter I made
if (!function_exists('my_acf_span_property')) {
function my_acf_span_property($value, $property) {
$value = '<span property="' . $property . '">' . $value . '</span>';
return $value;
}
}
if (!function_exists('my_acf_industry_value')) {
function my_acf_industry_value($value)
{
return my_acf_span_property($value, 'industry');
}
}
add_filter('acf/format_value/name=industry', 'my_acf_industry_value');
I made one filter for each ACF I need to change, this is only one as example.
I've tried to debug the filter changing return $value; to return htmlentities($value); in the function my_acf_span_property and the attributes are rendered in the frontend.
The output was expected to be <span property="industry">ACF value</span>
But wat is rendered is <span>ACF value</span>
It could be an Elementor problem?
Any Idea?
I solved with an action to allow the attributes in the posts
if (!function_exists('allow_property_attribute')) {
function allow_property_attribute() {
global $allowedposttags, $allowedtags;
$newattribute = "property";
$allowedposttags["span"][$newattribute] = true;
$allowedtags["span"][$newattribute] = true;
$allowedposttags["div"][$newattribute] = true;
$allowedtags["div"][$newattribute] = true;
$allowedposttags["p"][$newattribute] = true;
$allowedtags["p"][$newattribute] = true;
}
}
add_action( 'init', 'allow_property_attribute' );
It looks like was WordPress my problem, and not Elementor or ACF.
I want to add a simple code to all new post by default
I tried to used this code in .function.php (wpbeginner)
add_filter( 'default_content', 'my_editor_content' );
function my_editor_content( $content ) {
$content = "If you like this post, then please consider retweeting it or sharing it on Facebook.";
return $content;
}
I am using plugin named Shortcodes Ultimate
Code:
[su_spoiler title="Download The File" style="fancy" icon="chevron-circle"]Here[/su_spoiler]
I tried to normal use simple html and CSS code but it show the same error for both cases
https://i.stack.imgur.com/wgAs4.png
Try this -: wrap your code is a single quote as you are already using double quotes.
add_filter( 'default_content', 'my_editor_content' );
function my_editor_content( $content ) {
$content = '[su_spoiler title="Download The File" style="fancy" icon="chevron-circle"]Here[/su_spoiler]';
return $content;
}
I am trying to parse this site (to get the img-link): http://statigr.am/feed/parishilton
This is my code:
include 'parse/simple_html_dom.php';
// Create DOM from URL or file
$html = file_get_html('http://statigr.am/feed/parishilton/');
// Find all images
foreach($html->find('img') as $element)
{
echo $element->src . '<br>';
}
The script doesn't return anything! Why is that ? I want the img link.
It's because all images are inside CDATA section and parser ignores it, so the solution is
$html = file_get_html('http://statigr.am/feed/parishilton/');
$html = str_replace("<![CDATA[","",$html); // clean-up
$html = str_replace("]]>","",$html); // clean-up
$html = str_get_html($html); // re-construct the dom object
// Loop
foreach($html->find('item description img') as $el)
{
echo $el->src . "<br />";
}
Replace all CDATA from the returned content and then use str_get_html to create DOM object from that string and loop through the images. (Tested and works).
Output :
http://distilleryimage3.s3.amazonaws.com/cc25d8562c9611e3a8b922000a1f8ac2_8.jpg
http://distilleryimage7.s3.amazonaws.com/4d8e22da2c8911e3a6a022000ae81e78_8.jpg
http://distilleryimage5.s3.amazonaws.com/ce6aa38a2be711e391ae22000ae9112d_8.jpg
http://distilleryimage3.s3.amazonaws.com/d64ab4c42bc811e39cbd22000a1fafdb_8.jpg
......
......
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
i need to speed up my Wordpress blog. I searched around the web, but no success.
I want to minify or compress my output html code on one(single) line, like Matt Cutt's blog.
I tried W3TC, WP Minify and many others, but without result.
I need script, plugin, function or something that works.
Thanks in advance.
Here is one solution what I give in WordPress.StackExchange.com
https://wordpress.stackexchange.com/a/227896/82023
Generaly, in index.php you can place one code what will compress your HTML using regex. i made and use this on many places and work fine. Is not complete inline but do it's job.
<?php
/**
* Front to the WordPress application. This file doesn't do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* #package WordPress
*/
/**
* Tells WordPress to load the WordPress theme and output it.
*
* #var bool
*/
define('WP_USE_THEMES', true);
/** Manualy compress WP by Ivijan-Stefan Stipic **/
function compressorCF($str)
{
// clear HEAD
$str = preg_replace_callback('/(?=<head(.*?)>)(.*?)(?<=<\/head>)/s',
function($matches) {
return preg_replace(array(
/* Fix HTML */
'/\>[^\S ]+/s', // strip whitespaces after tags, except space
'/[^\S ]+\</s', // strip whitespaces before tags, except space
'/\>\s+\</', // strip whitespaces between tags
), array(
/* Fix HTML */
'>', // strip whitespaces after tags, except space
'<', // strip whitespaces before tags, except space
'><', // strip whitespaces between tags
), $matches[2]);
}, $str);
// clear BODY
$str = preg_replace_callback('/(?=<body(.*?)>)(.*?)(?<=<\/body>)/s',
function($matches) {
return preg_replace(array(
'/<!--(.*?)-->/s', // delete HTML comments
'#\/\*(.*?)\*\/#s', // delete JavaScript comments
/* Fix HTML */
'/\>[^\S ]+/s', // strip whitespaces after tags, except space
'/[^\S ]+\</s', // strip whitespaces before tags, except space
'/\>\s+\</', // strip whitespaces between tags
), array(
'', // delete HTML comments
'', // delete JavaScript comments
/* Fix HTML */
'>', // strip whitespaces after tags, except space
'<', // strip whitespaces before tags, except space
'><', // strip whitespaces between tags
), $matches[2]);
}, $str);
return $str;
}
/** Loads the WordPress Environment and Template */
ob_start();
require_once( dirname( __FILE__ ) . '/wp-blog-header.php' );
$content=ob_get_clean();
//echo $content;
echo compressorCF($content);
This is really not the best way to speedup your site. If you do it in the template it make the files unreadable and hard to maintain for less than 1% speedup. If you do it with a plugin that process the output, it will slow down the render.
Make sure :
You use as few plugins as possible, for example it's much faster to copy tracking code (google analytics or such) in footer.php than using a plugin
You have compiled, cleaned, minifyied CSS and JS that is on your server and properly compressed files.
You use CDN for all files that are on CDN like JQuery on https://developers.google.com/speed/libraries/devguide
Put mod_expire on your server and set expire date for media files far in future with .htaccess . This will prevent browsers from checking if files have changed (all the 200 status code you see in network traffic analysis)
Cache content using WP supercache or similar plugin
Install APC cache with enough memory (at least 32M for a single WP installation)
If your plugin loads CSS and JS files properly there is no point to say that they will make your website slow.
1. Another issue is how many database call these plugin make to render a particular task.
2. Whether that plugin check data from a remote server to update something like akismat and jetpack, thus makes these two pluin the most resource hungry.
Proper coded theme can help you to load your website properly. like my own site ( http://www.binarynote.com ) score loads score is 99/100 in getmetrix.com
We have Just developed a code in C++ using that we can compress any code. The main function is given here for your ready reference.
//function to compress text files
void compress(char source[], char dest[])
{
ifstream fin(source);
ofstream fout(dest);
char ch;
int sp=0;
while(fin.get(ch))
{
if(ch==' '||ch=='\t')
sp++;
else
sp=0;
if(ch=='\n' || ch=='\r')
fout<<' ';
else
if(sp>=1)
fout<<' ';
else
fout<<ch;
}
fin.close();
fout.close();
}
Put this code to function.php:
class WP_HTML_Compression
{
// Settings
protected $compress_css = true;
protected $compress_js = true;
protected $info_comment = true;
protected $remove_comments = true;
// Variables
protected $html;
public function __construct($html)
{
if (!empty($html))
{
$this->parseHTML($html);
}
}
public function __toString()
{
return $this->html;
}
protected function bottomComment($raw, $compressed)
{
$raw = strlen($raw);
$compressed = strlen($compressed);
$savings = ($raw-$compressed) / $raw * 100;
$savings = round($savings, 2);
return '<!--HTML compressed, size saved '.$savings.'%. From '.$raw.' bytes, now '.$compressed.' bytes-->';
}
protected function minifyHTML($html)
{
$pattern = '/<(?<script>script).*?<\/script\s*>|<(?<style>style).*?<\/style\s*>|<!(?<comment>--).*?-->|<(?<tag>[\/\w.:-]*)(?:".*?"|\'.*?\'|[^\'">]+)*>|(?<text>((<[^!\/\w.:-])?[^<]*)+)|/si';
preg_match_all($pattern, $html, $matches, PREG_SET_ORDER);
$overriding = false;
$raw_tag = false;
// Variable reused for output
$html = '';
foreach ($matches as $token)
{
$tag = (isset($token['tag'])) ? strtolower($token['tag']) : null;
$content = $token[0];
if (is_null($tag))
{
if ( !empty($token['script']) )
{
$strip = $this->compress_js;
}
else if ( !empty($token['style']) )
{
$strip = $this->compress_css;
}
else if ($content == '<!--wp-html-compression no compression-->')
{
$overriding = !$overriding;
// Don't print the comment
continue;
}
else if ($this->remove_comments)
{
if (!$overriding && $raw_tag != 'textarea')
{
// Remove any HTML comments, except MSIE conditional comments
$content = preg_replace('/<!--(?!\s*(?:\[if [^\]]+]|<!|>))(?:(?!-->).)*-->/s', '', $content);
}
}
}
else
{
if ($tag == 'pre' || $tag == 'textarea')
{
$raw_tag = $tag;
}
else if ($tag == '/pre' || $tag == '/textarea')
{
$raw_tag = false;
}
else
{
if ($raw_tag || $overriding)
{
$strip = false;
}
else
{
$strip = true;
// Remove any empty attributes, except:
// action, alt, content, src
$content = preg_replace('/(\s+)(\w++(?<!\baction|\balt|\bcontent|\bsrc)="")/', '$1', $content);
// Remove any space before the end of self-closing XHTML tags
// JavaScript excluded
$content = str_replace(' />', '/>', $content);
}
}
}
if ($strip)
{
$content = $this->removeWhiteSpace($content);
}
$html .= $content;
}
return $html;
}
public function parseHTML($html)
{
$this->html = $this->minifyHTML($html);
if ($this->info_comment)
{
$this->html .= "\n" . $this->bottomComment($html, $this->html);
}
}
protected function removeWhiteSpace($str)
{
$str = str_replace("\t", ' ', $str);
$str = str_replace("\n", '', $str);
$str = str_replace("\r", '', $str);
while (stristr($str, ' '))
{
$str = str_replace(' ', ' ', $str);
}
return $str;
}
}
function wp_html_compression_finish($html)
{
return new WP_HTML_Compression($html);
}
function wp_html_compression_start()
{
ob_start('wp_html_compression_finish');
}
add_action('get_header', 'wp_html_compression_start');
on https://photogrist.com it's works fine :)