File functions.php is file located inside your theme or your child theme. If this file not exist in your child theme – you can create this file.
Remember: When you has an error in your functions.php – the frontend of your website couldn’t working.
Wordpress Developer, Samples, Code Snippets
File functions.php is file located inside your theme or your child theme. If this file not exist in your child theme – you can create this file.
Remember: When you has an error in your functions.php – the frontend of your website couldn’t working.
When you need, you can add to the textwidget php script. In standard version, this not work, but after added simple code in your child theme in file: functions.php, your php code will be executed.
function uniset_php_execute($html){ if(strpos($html,"<"."?php")!==false){ ob_start(); eval("?".">".$html); $html=ob_get_contents(); ob_end_clean(); } return $html; } add_filter('widget_text','uniset_php_execute',99);
After that, In your textwidget add simple script, to try it. For example:
<?php echo "Some random number: <pre>".rand()."</pre>"; ?>
NOTICE: For security reasons this code is not recommended, you should not use this code on production website, but sometimes it is usable for programmers to display environment variables or for other programming needs: we can check your cache and some other reasons.
I you want to add after the_content any text, you need add code in your functions.php:
function arkadiuszbartnik_com_add_after_content($content) { return $content."After_content_text"; } add_filter("the_content","arkadiuszbartnik_com_add_after_content",10,1);
In few my works i need use shortcode inner text widget. When you need add custom gallery or other shortcodes you can add this code in your functions.php:
<?php /* Allow shortcodes in widget areas */ add_filter('widget_text', 'do_shortcode'); ?>
Simple? Please share this post to your friends.
In your functions.php
add:
<?php function arkadiuszbartnik_com_add_before_content($content) { return "Before_Content".$content } add_filter("the_content","arkadiuszbartnik_com_add_before_content",10,1);
When you need autoremove featured image from the post – when the post will be deleted, please add code:
<?php add_action( 'before_delete_post', 'arkadiuszbartnik_remove_attachment_with_post', 10 ); function arkadiuszbartnik_remove_attachment_with_post($post_id) { if(has_post_thumbnail( $post_id )) { $attachment_id = get_post_thumbnail_id( $post_id ); wp_delete_attachment($attachment_id, true); } }