Add default code in wordpress post - html

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;
}

Related

Passing down MediaWiki template arguments to custom HTML attributes

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}}} }}

Yii2 mpdf with barcode-generator

I'm using yii2 and installed two extension : mpdf , and yii2-barcode-generator-8-types.
Both of them were installed and configured properly and working well.
But what I can't do is to load barcode into pdf.
Here is my code :
Controller :
public function actionPdf()
{
$pdf = Yii::$app->pdf;
$pdf->content = $this->renderPartial('_pdf');
echo $this->renderPartial('_pdf');exit;
return $pdf->render();
}
View :
<div id="showBarcode"></div>
<?php
use barcode\barcode\BarcodeGenerator as BarcodeGenerator;
$optionsArray = array(
'elementId'=> 'showBarcode',
'value'=> '12345678',
'type'=>'code128',
);
echo BarcodeGenerator::widget($optionsArray);
?>
And it show something like this
but If I try to delete all code inside actionPdf() and just write
return $this->render("_pdf");
it show like this:
Please help!!!
I think your controller should be this
public function actionPdf()
{
$pdf = Yii::$app->pdf;
$pdf->content = $this->renderPartial('_pdf');
return $pdf->render();
}
The row with echo $this->renderPartial('_pdf');exit; don't must be used because it prevents the program to invoke correctly the render of the pdf page. If you use this instruction you displays only the render of "html like code" page like you see in result you posted moreover immediately after this instruction you exit form action without invoking the $pdf->render.

Adding a separator after each article in Wordpress

I need to use an image to separate my articles (posts). I found this function below
function funny_cat_filter( $content ) {
$content .= '<img src="(image url)"/>';
return $content;
}
add_filter( 'the_content', 'funny_cat_filter' );
Don't mind the function name. This works just fine but with one little pesky detail. It adds image on pages also and I don't want that. I want this only to be added after each post not on every single page.
How do I do that?
You can check if you are in a post with is_single() or in the home with is_home().
function funny_cat_filter( $content ) {
if (is_single() || is_home())
$content .= '<img src="(image url)"/>';
return $content;
}
add_filter( 'the_content', 'funny_cat_filter' );

WordPress Shortcode adding attributes

I'm writing a shortcode function for WP. Inside the function I have the $content (in this case an image). I need to be able to add a couple attributes to that content and return it in a string, like so:
function Shortcode( $atts, $content=null ){
if(!is_null($content){
return '<div class="wrapper">'. $content .'</div>'
}
}
Currently, just the image is getting spit back, but I need to somehow modify it and add a couple attributes before adding it to the string above.
I need to do something like this:
function Shortcode( $atts, $content=null ){
if(!is_null($content){
// CONVERT $CONTENT TO STRING
$content_html=somefunction($content)
echo $content_html; // <img src='....' />
return '<div class="wrapper">'. $content_html .'</div>'
}
}

Output post for second wordpress editor

I recently added a new editor to all my pages and posts admin area with the Wordpress 3.3 new feature to do this
add_action( 'edit_page_form', 'my_second_editor' );
function my_second_editor() {
// get and set $content somehow...
wp_editor( $content, 'mysecondeditor' );
}
My question is how do I output what I enter in this second editor on my website/page? Do I need to make a custom loop? The codex is not very helpful unfortunately.
Thanks
You'll need get_post_meta(), use it like:
echo get_post_meta(get_the_id(), 'mysecondeditor');
Read more: http://codex.wordpress.org/Function_Reference/get_post_meta
To save the data entered in your second editor you'll need this code in your functions.php file:
add_action( 'save_post', 'save_post', 10, 2 );
function save_post( $post_id, $post ) {
if ( !current_user_can( 'edit_post', $post_id ) )
return $post_id;
update_post_meta( $post_id, 'mysecondeditor', stripslashes( $_POST['mysecondeditor'] ) );
}
So after that he's the full code for your second editor:
wp_editor( get_post_meta(get_the_id(), 'mysecondeditor', true), 'mysecondeditor' );
The true above makes sure only a single variable is returned and not an array so you can use it right away.
user2019515I's (Apr 18 '13 at 12:06) answer works for me, I can add text and gallery, but when I display that with this code:
<?php echo get_post_meta(get_the_ID(),'mysecondeditor')['0']; ?>
I got gallery code instead of the images, so:
mytext [gallery ids="102,62"]
How could I display the text (mytext) and the images too?