after_setup_theme always runs

SOLUTION: after_switch_theme does exactly what I intended here. It fires after the theme is switched TO your theme. One of the solutions mentioned below uses switch_theme. This does not have the desired results, since it only happens upon switching away from your theme. Here is an article that I found as reference: http://core.trac.wordpress.org/ticket/7795#comment:29 Here is … Read more

Get the first image from post content (eg.: hotlinked images)

If you want display an image that is inserted into your content (a hotlinked image, for example), you must use a function like this (source): add in functions.php: function catch_that_image() { global $post, $posts; $first_img = ”; ob_start(); ob_end_clean(); $output = preg_match_all(‘/<img.+src=[\'”]([^\'”]+)[\'”].*>/i’, $post->post_content, $matches); $first_img = $matches [1] [0]; if(empty($first_img)){ //Defines a default image $first_img … Read more

The proper way to include/require PHP files in WordPress

If you check https://codex.wordpress.org/Function_Reference/get_template_directory_uri You will see get_template_directory_uri() returns a uri, not a server path. You should use instead the get_template_directory() function: include get_template_directory() . ‘subdir/filename.php’; For a plugin you can use the plugin_dir_path() function: include plugin_dir_path( __FILE__ ) . ‘subdir/filename.php’;

Can I create my own “Recent Posts” widget or customize the existing one?

It’s usually best to copy the existing one, name it something unique, and then add your own functionality. Copy the WP_Widget_Recent_Posts class from wp-includes/class-wp-widget-recent-posts.php into your functions.php (or, preferably, another file in your theme devoted just to widgets) and rename to something else, like My_Widget_Recent_Posts Add your functionality in there. Don’t forget to call register_widget(‘My_Widget_Recent_Posts’) … Read more

deneme bonusu veren sitelerbahis casinomakrobetceltabetpinbahispolobetpolobet girişpinbahis girişmakrobet girişpulibet girişmobilbahis girişkolaybet giriş