Modify text by image

How to replace the text with the site name for a logo on the login page and after login, in the top left of the main page?
  • Advanced way is to override this file in your custom plugin.

    (You can start with this skeleton plugin.)

    Create a new folder 'assets' in your data directory.

    Put your logo to this folder, e.g.:

    assets/topbar_logo.png

    Copy the mentioned file to your custom plugin and change code on:

    $asset_src = elgg_get_simplecache_url('assets/topbar_logo.png');
    
    
    $logo = elgg_format_element('img', [
        'src' => $asset_src,
        'alt' => elgg_get_site_entity()->getDisplayName(),
    ]);
    
    
    echo elgg_format_element('div', [
        'class' => 'elgg-heading-site'
    ], elgg_view('output/url', [
        'text' => $logo,
        'href' => elgg_get_site_entity()->getURL(),
        'title' => elgg_get_site_entity()->getDisplayName(),
    ]));
     
    Activate your custom plugin.
     
    The easiest way is to use this plugin.
     
    Read also the recent discussion about it.
  • Thanks Nikolai,

    It's very hard, but i will try

  • I tried the advanced method, but unfortunately the logo isn't loading/showing. The browser console states

    "Graphic could not be loaded."

    Edge shows an image placeholder. The URL of it is

    [mydomain]/cache/[anumbercode]/default/assets/topbar_logo.png

    When following the link, I get the message

    "Requested view is not an asset"

    I invalidated the cache and clicked on "upgrade" in the admin area. SimpleCache is activated.

    What could be the reason for the image to not show?

  • Oops, that was my mistake.
    I forgot to specify that the 'assets' folder location needs to be defined in elgg-plugin.php:
     
    'views' => [
        'default' => [
          'assets/' => elgg_get_data_path() . 'assets/',
        ],
    ],
     
    However, you can place this folder/file to your custom plugin instead of /data directory:
     
    /mod/my_plugin/views/default/assets/topbar_logo.png
     
    Then everything will work without additional code in elgg-plugin.php file.
     
    The cache needs to be cleared after making changes.

     

  • Awesome! It works like a charm now. Thank you for the update.

    Since I already created the assets folder, I chose to add the "views" bit to my elgg-plugin.

    A beautifully styled little logo can make quite the difference for the layout. :)

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking