Some of the small but useful code for WordPress

Add the below Functions in your function.php File

1) PHP execution in Widget, Post and Page Editor of WordPress
add_filter(‘wp_post’,’execute_php’,100);
add_filter(‘widget_text’,’execute_php’,100);
add_filter(‘the_content’,’execute_php’,100);
function execute_php($html){
if(strpos($html,”<“.”?php”)!==false){
ob_start();
eval(“?”.”>”.$html);
$html=ob_get_contents();
ob_end_clean();
}
return $html;
}

2) Hide Top Admin Bar from website when u logged in at admin panel in wordpress
add_filter(‘show_admin_bar’, ‘__return_false’);

3)  Add a Favicon in for ur admin panel and login page in wordpress

//First, create a function that includes the path to your favicon
function add_favicon() {
$favicon_url = get_stylesheet_directory_uri() . ‘/images/favicon/favicon.ico’;
echo ‘<link rel=”shortcut icon” href=”‘ . $favicon_url . ‘” />’;
}
// Now, just make sure that function runs when you’re on the login page and admin pages
add_action(‘login_head’, ‘add_favicon’);
add_action(‘admin_head’, ‘add_favicon’);

4) Remove Update Notification of Individual Plugin in WordPress
function filter_plugin_updates( $value ) {
unset( $value->response[‘wordpress-bootstrap-css/hlt-bootstrapcss.php’] );
return $value;
}
add_filter( ‘site_transient_update_plugins’, ‘filter_plugin_updates’ );

5) Remove WordPress logo from admin bar
function annointed_admin_bar_remove() {
global $wp_admin_bar;

$wp_admin_bar->remove_menu(‘wp-logo’);

}

add_action(‘wp_before_admin_bar_render’, ‘annointed_admin_bar_remove’, 0);

6) Removing Auto <p> Generated in WordPress
remove_filter( ‘the_content’, ‘wpautop’ );

7) Custom Fonts To Admin Panel
function my_custom_fonts() {
echo ‘
body, td, textarea, input, select {
font-family: “Lucida Grande”;
font-size: 14px;
}
‘;
}
add_action(‘admin_head’, ‘my_custom_fonts’);

8)  CUSTOM ADMIN LOGIN HEADER LOGO
function my_custom_login_logo()
{
echo ‘<style type=”text/css”> h1 a { background-image:url(‘ . get_bloginfo(‘template_directory’) . ‘/images/assets/logo_admin.png) !important; } </style>’;
}
add_action(‘login_head’, ‘my_custom_login_logo’);

9)  CUSTOM ADMIN LOGIN LOGO LINK
function change_wp_login_url()
{
echo bloginfo(‘url’); // OR ECHO YOUR OWN URL
}
add_filter(‘login_headerurl’, ‘change_wp_login_url’);

10)  CUSTOM ADMIN LOGIN LOGO & ALT TEXT
function change_wp_login_title()
{
echo get_option(‘blogname’); // OR ECHO YOUR OWN ALT TEXT
}
add_filter(‘login_headertitle’, ‘change_wp_login_title’);

Advertisements

One thought on “Some of the small but useful code for WordPress

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s