Remove WordPress admin icons or SVG's - wordpress

I am finding people are choosing Squarespace etc simply because the backend menu is less confusing. I love WordPress and would like to simplify the backend without a plugin.
I am starting by trying to remove icons and SVG's added by plugins. I can remove Woocommerce for example by this code I found
add_action("admin_menu", function () {
foreach ($GLOBALS["menu"] as $position => $tab) {
if ("woocommerce" === $tab["2"]) {
$GLOBALS["menu"][$position][6] = "";
break;
}
}
});
It's not ideal, and l'd like to use code to remove them in a cleaner fashion, I am aware there are plugins that do it which makes me sure that it can be done programmatically but my experience precludes me from knowing how.
While this works for Woocommerce, I'd like to remove them all as whilst I'm sure at some stage it was trendy or cute it would be nice if it was optional, I know that's a WordPress decision, but for now does anyone have a work around?

Related

How to customize Wordpress Theme before going live

Yesterday I installed a new theme on Wordpress on my self-hosted website. I am aware of the feature that allows you to preview a theme and have used it to select a new Theme that I want to install.
Problem
I do not want to interrupt normal operations of my website, but this new theme requires a lot of customization before it is ready to go. How do I do this?
My Crappy Solution
Is the only way to go about it to run a virtual server on my desktop? This seems tedious, not to mention all the errors I usually get when switching to the "real" server when doing this.
A better way?
I've been searching on SO as well as the WordPress Forum for an answer as to how to do this, but have come up short. I would have thought this is a common question. Maybe I'm using the wrong search terms [themes, customization, before installing]???
Any help is greatly appreciated! Thanks!
Ok, since your question is a pretty good one and probably not a few people are going through the same process when they decide to update their site, I decided to give a try to the get_stylesheet and get_template filter hooks. It turns out that with a very small plugin, you can easily enforce a specific theme(well in this case any logged-in visitor, but you can change this to use any logic you want) according to a specific rule/s.
Here's the code that you need to put in a file in your plugins directory:
<?php
/*
Plugin Name: Switch Theme
Description: Switches the theme for logged-in visitors, while keeping the current theme for everyone else. !!!NOTE!!! Please back-up your database prior using this plugin - I can't guarantee that it will work with any theme, nor that it won't break your site's set-up - USE AT YOUR OWN RISK(I did a quick test and it seemed to be fine, but haven't done extensive testing).
You don't need to switch to the desired theme before that - you want to keep active the theme that you will display to your visitors - the one that you will see will be used programatically.
Before activating the plugin, change the line that says `private $admin_theme = '';` to `private $admin_theme = 'theme-directory-name';` where "theme-directory-name" is obviously the name of the directory in which the desired theme resides in.
*/
class MyThemeSwitcher {
private $admin_theme = '';
function MyThemeSwitcher() {
add_filter( 'stylesheet', array( &$this, 'get_stylesheet' ) );
add_filter( 'template', array( &$this, 'get_template' ) );
}
function get_stylesheet($stylesheet = '') {
if ( is_user_logged_in() && $this->admin_theme ) {
return $this->admin_theme;
}
return $stylesheet;
}
function get_template( $template ) {
if ( is_user_logged_in() && $this->admin_theme ) {
return $this->admin_theme;
}
return $template;
}
}
$theme_switcher = new MyThemeSwitcher();
So - first of all BACKUP YOUR DATABASE! I tested locally with Twenty Eleven being the default theme and a basic framework theme as my custom theme - the theme options and navigation menus were saved properly.
Then all you need to do is to update the file(change the line that says private $admin_theme = ''; to private $admin_theme = 'theme-slug'; where theme-slug is the name of the directory in which the theme you want to use is).
Also - you won't be able to change the Front page and Posts page options, without this affecting the live site, nor will you be able to change the any shared components that both themes use(Site name, Front Page, Posts page, Posts Per Page, etc options, content and so on).
So if you have no clue whether this solution is for you - well, it depends.
If both themes are not relatively complex, then most-likely you should be able to use this hack. If they are though maybe you should do a second installation of your website as others suggested - I think that a second installation in either a sub-domain or a sub-directory would be the best option for you(simply because moving a multisite database is more complex than moving a normal WP database).
I'd setup local apache server with a wordpress installed to customize and test a new theme. When you finished customizing it then you can upload the theme to your live site and activate it. If there are settings that you need to set in the dashboard then you probably will have to adjust them again. That's one way to test/customize a theme before putting it live.
You could create a network (make WordPress multisite with define('WP_ALLOW_MULTISITE', true);, see : http://codex.wordpress.org/Create_A_Network) and then create one sub-site, then turn it "off" with a Maintenance plugin so it is not accessible to users not logged in as admin, export your posts & data from main blog, import them in sub-blog with WordPress default importer, then apply your new theme to this sub-blog and work on it. When everything satisfies you, apply the theme to the main site and deactivate subsite.

Drupal 6: Show Flags for Node Translations

For each node preview, I want to have little flag icons at the top representing the available translations. I have seen the language switcher code, but it outputs all the languages all the time. That is annoying because people will click their language and then find that the page is only available in English anyway (I have a site with many articles in a great variety of languages). I have seen this done though. I'm relatively new to Drupal programming. Can anyone give me a pointer?
Thanks!
Figured it out by myself, and noting it here because I know I'm not the only one with this issue.
The template I'm working off is called scaccarium, so I went to /themes/scaccarium/template.php and added the following function:
function scaccarium_preprocess_node(&$vars) {
$node = $vars['node'];
$translationlinks = array();
// Move translation links into separate variable
foreach ($node->links as $key => $value) {
if ($value['attributes']['class'] == 'translation-link') {
$translationlinks[$key] = $value;
// unset($vars['node']->links[$key]);
}
}
$vars['translationlinks'] = theme('links', $translationlinks, array('class' => 'links translationlinks inline'));
}
If your template is called something else, you should obviously go to a different folder and also change the first word of the function name. And if your theme comes with an existing _preprocess_node function, carefully modify it.
Then, I went to my template's node.tpl.php and I added
<?php if ($translationlinks) {
print $translationlinks;
} ?>
next to the title.
Then I had to clear the Drupal cache (even though caching was disabled!) in Performance > Caching in order to get this to work.
Done!
...
To add language links at the top of full nodes, I had to add another "print $translationlinks" at a different place in node.tpl.php as well, as the h3 title thing was just for node previews. Then, to remove the redundant language links at the bottom of full nodes, I tried that unset line that you see commented out in template.php - I found that it had no effect even though another website had recommended it. So what I ended up doing was using CSS for this, adding the following to my template's CSS file:
.node-links .translation-link {
display: none;
}
I hope that my experience will help someone else with the same problem.

drupal menu customizacion via css?

I've been fiddling around with drupal theming quite succesfully (or at least, that's what i think), but when I tried to inject css coding to the primary links menu to customize it as i generally do via html+css, i hit a wall.
I have been able to apply css styles to divs, links and text, but I would like to customize the primary (and secondary) links menus much more, perhaps with some css sprite menu techniques, but while remaining drupal-compliant and using as much of drupal's own php in the process. or if i really have to rewrite some code, i don't mind, though i am not quite the programmer yet.
i have been around several sites but i haven't anything particularly useful, so if anyone can point me to the right direction, i will be quite grateful.
thanx in advance.
You can add a id-like class for each menu item - add this function in your template.php
function mythemename_menu_item_link($link) {
if (empty($link['localized_options'])) {
$link['localized_options'] = array();
}
// LOOK HERE
// add a key for main menu items, so we can theme each item in a different way
// add this class only for a specific menu
if ($link['menu_name'] == 'menu-menu-mymenu') {
if ($link['localized_options']['attributes']['class']) {
$link['localized_options']['attributes']['class'] .= ' menu-'. $link['mlid'];
}
else {
$link['localized_options']['attributes']['class'] = 'menu-'. $link['mlid'];
}
}
return l($link['title'], $link['href'], $link['localized_options']);
}
This code can be cleaner, but i've added more lines so you can read it better.
if I understand your question correctly you will like to add a custom class/id to you menu . This can be done by overriding the theme_menu_tree for a given menu. I do this for my main menu by adding the following to my template.php file:
function THEMENAME_menu_tree__main_menu($variables){
return '<ul class="menu main-menu">' . $variables['tree'] . '</ul>';
}
hope this helps.
You should also have a look at the themer module, which gives you suggestion for template functions and more.
cheers,
Jørgen

Change management in WordPress

I have a beginner question. What is the best way to address the change management issues in WordPress? I have an all-pages WordPress installation. Suppose name of some event or an entity changes from A to B, then I have to go to all the pages to make that change. Is there any better way of doing it? Like externalization or something.
Or the way similar to how WordPress handle blog name using bloginfo() function. You change blog name at one place and it is reflected everywhere.
Thanks,
Paras
If a URL on your site changes, it is always wise to leave a redirect to the new page. This will help your visitors and search engines. If you create redirects, it doesn't matter too much if you still have a link to the old address in one of your posts. There will probably be a plugin for this, but I don't know which one.
If you really want to keep all links pointing to the latest version, you could replace them with shortcodes that are evaluated to the real URL. <a href="[linkto postid=123]"> would then result in <a href="/2010/08/05/some-post">. I think this is doable, but I don't know whether a plugin already exists for this.
You can also use this technique to replace short snippets, like your company name. The Shortcode API is really easy:
// [company_name]
function replace_company_name($atts) {
return "My Awesome Company";
}
add_shortcode('company_name', 'replace_company_name');
// More generic
// [replace r='company_name']
// [replace r='company_motto']
function do_replacement($atts) {
$replacements = array(
'company_name' => 'My Awesome Company',
'company_motto' => 'A Company so Awesome even you would want to work here!',
);
return $replacements[$atts['r']];
}
add_shortcode('replace', 'do_replacement');
You can hardcode the strings in your plugin code, or you could create a Wordpress options page where users can add and edit new shortcodes.

Drupal administration theme doesn't apply to Blocks pages (admin/build/block)

A site I'm creating for a customer in D6 has various images overlaying parts of the main content area. It looks very pretty and they have to be there for the general effect.
The problem is, if you use this theme in the administration pages, the images get in the way of everything.
My solution was to create a custom admin theme, based on the default one, which has these image areas disabled in the output template files - page.tpl.php
The problem is that when you try and edit the blocks page, it uses the default theme and half the blocks admin settings are unclickable behind the images. I KNOW this is by design in Drupal, but it's annoying the hell out of me and is edging towards "bug" rather than "feature" in my mind. It also appears that there is no way of getting around it.
You can edit /modules/blocks/block.admin.inc to force Drupal to show the blocks page in the chosen admin theme. BUT whichever changes you then make will not be transferred to the default theme, as Drupal treats each theme separately and each theme can have different block layouts. :x
function block_admin_display($theme = NULL) {
global $custom_theme;
// If non-default theme configuration has been selected, set the custom theme.
// $custom_theme = isset($theme) ? $theme : variable_get('theme_default', 'garland');
// Display admin theme
$custom_theme = variable_get('admin_theme', '0');
// Fetch and sort blocks
$blocks = _block_rehash();
usort($blocks, '_block_compare');
return drupal_get_form('block_admin_display_form', $blocks, $theme);
}
Can anyone help? the only thing I can think of is to push the $content area well below the areas where the image appear and use blocks only for content display.
Thanks!
in template.php you can put
function YOURTHEME_preprocess_page(&$vars) {
if (implode('/', arg()) == 'admin/build/block'){
$vars['body_classes'] = $vars['body_classes'].' administer_block';
}
}
and you'll have a nice body class which you can use to hide those images using CSS.
If anyone's still having a problem with this, a bit similar to barraponto's solution above, if you are using the admin menu module, it adds a class (.admin-menu) to the body, which you can use to hide any overlaying divs etc that are getting in the way.
you can apply admin theme wherever you want using hook_init() in your custom module:
function yourmodule_init()
{
if ( some condition here like arg(0) == 'foobar'
or node_load(arg(1))->type == 'something' )
{
$GLOBALS['custom_theme'] = variable_get('admin_theme', '0');
drupal_add_css(drupal_get_path('module', 'system') .'/admin.css', 'module');
drupal_add_js(drupal_get_path('theme', 'myadmintheme').'/jscripts/adminjs.js');
}
}
EDIT: then (probably) you have to use form_alter against the block editing form to restore the target theme. in this way you don't have to hack the core.
Thanks for bringing up this topic! I was having the same problem, and it's annoying. Here's how to remedy it without a single line of code:
1) Switch the main theme to your administration theme.
2) Configure Blocks. This always affects the currently selected main theme.
3) Switch the main theme back to what it's supposed to be. Your admin theme will still reflect your changes.
could just use the block-admin..... tpl file from block module and theme it in your custom theme. I have done this way as admin theme module never overrides block admin even when you use custom path bit.
If you don't need your new theme while performing administration tasks, you can use a different theme while doing so.
Goto "Site Configuration" -> "Administration Theme". Here you can pick the theme to be used while doing admin. So your new theme is only used while users are viewing your site. And you can do admin tasks without the interference of all your images.

Resources