How to add iOS & fav icons to the theme?

Hook into wp_head in your functions.php file. add_action(‘wp_head’, ‘add_your_stuff’); function add_your_stuff() { ?> <link rel=”shortcut icon” href=”https://wordpress.stackexchange.com/questions/157869/<?php echo get_stylesheet_directory_uri();?>/favicon.ico” type=”image/x-icon” /> <link rel=”apple-touch-icon” href=”<?php echo get_stylesheet_directory_uri();?>/apple-touch-icon.png” /> <link rel=”apple-touch-icon” sizes=”57×57″ href=”<?php echo get_stylesheet_directory_uri();?>/apple-touch-icon-57×57.png” /> <link rel=”apple-touch-icon” sizes=”72×72″ href=”<?php echo get_stylesheet_directory_uri();?>/apple-touch-icon-72×72.png” /> <link rel=”apple-touch-icon” sizes=”76×76″ href=”<?php echo get_stylesheet_directory_uri();?>/apple-touch-icon-76×76.png” /> <link rel=”apple-touch-icon” sizes=”114×114″ href=”<?php echo get_stylesheet_directory_uri();?>/apple-touch-icon-114×114.png” /> … Read more

Setting cookies in WordPress

Change this line setcookie( ‘cookiename’, ‘cookievalue’, time() + 3600, ‘mysite.net/sites/site1/’, ‘mysite.net/sites/site1/’); to setcookie( ‘cookiename’, cookievalue, time() + 3600, COOKIEPATH, COOKIE_DOMAIN);` COOKIEPATH and COOKIE_DOMAIN are WP constants now, but the codex is not updated yet.

Pages should have priority when using add_rewrite_rule

If I understand you correctly, you could try to replace: add_rewrite_rule( ‘^prefix-(.*)’, ‘foo/bar/index.php?page=$matces[1]’, ‘top’ ); with add_rewrite_rule( ‘^prefix-(.*)’, ‘foo/bar/index.php?page=$matces[1]’, ‘bottom’ ); From the Codex: ‘top‘ will take precedence over WordPress’s existing rules, where ‘bottom‘ will check all other rules match first. Default: “bottom“

Insert width & height attributes to all images displayed on each page

Tested and confirmed that this works: add_filter( ‘the_content’, ‘add_image_dimensions’ ); function add_image_dimensions( $content ) { preg_match_all( ‘/<img[^>]+>/i’, $content, $images); if (count($images) < 1) return $content; foreach ($images[0] as $image) { preg_match_all( ‘/(alt|title|src|width|class|id|height)=(“[^”]*”)/i’, $image, $img ); if ( !in_array( ‘src’, $img[1] ) ) continue; if ( !in_array( ‘width’, $img[1] ) || !in_array( ‘height’, $img[1] ) ) … Read more

Why functions.php file is called 8 time for just one page load?

Add a plugin like Kint Debugger + Debug Bar and add the following code to your functions.php. global $wp; ob_start(‘kint_debug_ob’); d($wp); ob_end_flush(); When you check the Debug Bar you should see the backtrace which will tell you which order functions were fired in. Loading 8 times is quite high for a single request. There is … Read more

Display a function using AJAX

You’re not hooking the function to wp_ajax correctly. You need to replace the my_action part with your action name that you’re using the in AJAX request. In your case it’s display_user_table. You also need to hook it on to wp_ajax_nopriv so that it works for logged out users. Here’s your hook with those changes: add_action(‘wp_ajax_diplay_user_table’, … Read more

Develop function get_template_part in functions.php

get_template_part is echoing the HTML code. and the shortcode function must return the content. then you can try that : function custom_code($attr, $content, $tag) { ob_start(); get_template_part( ‘page’, ‘example’ ); $content = ob_get_clean(); return $content; } add_shortcode( ‘custom’, ‘custom_code’ );

Allow latex in wordpress excerpt

If I’m not mistaken, this could be as simple as add_filter(‘get_the_excerpt’, ‘latex_markup’); if the Latex markup isn’t removed by another filter before that (it shouldn’t, I believe). latex_markup is the function jetpack adds to the list of filters on the_content. It might get interesting when your latex code is at the edge of the excerpt … Read more

Add a new subscriber role using a function

A subscriber has only 1 capability namely: read To create a new (custom)role just add following code-lines in functions.php. Please make back-up first and so on…. When added to functions.php go into the back-end and check if you can add an (new or existing) user to this role. When all is working you can delete … Read more

Changes to functions.php not working

Closing PHP tag and then opening in the next line: Whenever there is something (even space, tab, newline etc.) after a closing PHP tag ?> or before an opening PHP tag <?php, PHP engine considers it as output. So the way your code is, it’ll generate some unnecessary output, that often throws error or warning … Read more