The post Run code when theme is activated in WordPress first appeared on Agichevski.
]]>What you can do is
There are 2 ways how this can be done and both ways are different…
First one is right away after activating theme but this involves executing code on every page load, which means with every refresh that code is executed.
In below example I remove 2 features that I don’t want to be used in my theme and those are:
1. Users to be able to add custom background WP Reference
2. Users to be able to add custom header WP Reference
So because in my theme they will be able to set custom header and background I want to disable those options from WP Admin.
add_action( 'after_setup_theme','remove_options', 100 );
function remove_options() {
remove_custom_background();
remove_custom_image_header();
}
So what we do first is creating function ‘remove_options’ where we add the predefined wordpress function for disabling these options. After that we just add_action hook where we point that after setting up theme execute those commands.
So here comes main and important part where you need to execute code only once when theme is activated and never again. I use this to create records in database, add categories, pages everything that is needed to integrate my theme.
It is weird because there is not predefined function or hook from wordpress that you can use for this, so we must create our code that will do that.
I found a very simple solution which works for me in any theme and any wordpress version.
if ( is_admin() && isset($_GET['activated'] ) && $pagenow == "themes.php" ) {
wp_insert_term('News', 'category');
wp_insert_term('Business', 'category');
wp_insert_term('Gaming', 'category');
wp_insert_term('Entertainment', 'category');
wp_insert_term('Lifestyle', 'category');
}
In above code after setting up code we insert 5 categories into WordPress. So mainly what we do is check is it theme page, does it exist activated parameter and are we in admin.
If all these conditions are fulfilled then that code will execute.
The post Run code when theme is activated in WordPress first appeared on Agichevski.
]]>The post WordPress.com Dashboard with new and clean look first appeared on Agichevski.
]]>In April Matt Thomas from Automatic announced creating better and nicer design on WordPress.com Dashboard and finally is done.
His goals were:
So let’s see what is changed in new look on WordPress Dashboard…
First that comes to my eyes is the left menu which has darker colors and new icons. The icons are redrawn and cleaner and there is bigger space which looks really clean and nice.
Main typography is changed to new font Open Sans which covers 897 characters including Latin, ISO Latin and Cyrillic and adds additional cleaner look to the menu.
The new design is optimized for using also on smartphones and tablets so in future if you want to do posts on your blog you don’t need the official mobile application.
So overall because I’m fan on clean design I think the new changes are positive and good.
Other user feedback regarding the new changes is good and bad as always… there are lot of positive comments about the new clean look but also negative comments regarding the dark colors used on menu and asking the grey lighter color to get back.
The post WordPress.com Dashboard with new and clean look first appeared on Agichevski.
]]>