Skip to content
  • Recent
  • Tags
  • Popular
  • Users
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

Lay Theme Forum

  1. Home
  2. General Discussion
  3. Replace some element of page title

Replace some element of page title

Scheduled Pinned Locked Moved General Discussion
5 Posts 4 Posters 637 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nathalie
    wrote on last edited by Nathalie
    #1

    Hello There,

    The idea is to take the page title, replace some of their element and show it into class div "projectname".

    Currently, i have the — replace by Projet - but i would like to delete the Sitename and not show it into "projectname" div ( but still show it into page title).

    Page title is set like this

    <?php
    $title = get_bloginfo('name');
    if(!is_front_page()){ 
    $title .= ' &mdash; '.trim(wp_title('',false));
    }
    ?>
    

    My script is set like this

    Frontend.GlobalEvents.on("newpage",function(e,l,t){
    if("project"===l){
    var a=document.title.replace("—","<i>Stuff - </i>");
    jQuery("li.projectname").html(a)}
    

    The idea is to take the page title, replace some of their element and show it into class div "projectname".

    Currently, i have the — replace by Projet - but i would like to delete the Sitename and not show it into "projectname" div ( but still show it into page title).

    Thanks

    1 Reply Last reply
    0
    • arminunruhA Online
      arminunruhA Online
      arminunruh
      Global Moderator
      wrote on last edited by
      #2

      Hey Nathalie!

      So if I understood it right you want to do this:

      var title = document.title;
      //lets say your title is: Site Name – Project Name
      //To get only the project name you need to do:
      title = title.substr(12);
      
      //Now var title is just "Project Name" because I extracted all characters after the 12th
      
      

      https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr

      1 Reply Last reply
      0
      • N Offline
        N Offline
        Nathalie
        wrote on last edited by
        #3

        @arminunruh said:

        substr(12)

        Perfect Armin! The .substr was exactly what i needed ! You are great as always !
        Thanks

        1 Reply Last reply
        1
        • X Offline
          X Offline
          xvalerax
          wrote on last edited by
          #4

          @nathalie said in Replace some element of page title:

          function

          hi, also want switch sitename and page title, how to do that?

          1 Reply Last reply
          0
          • mariusjopenM Offline
            mariusjopenM Offline
            mariusjopen
            Global Moderator
            wrote on last edited by
            #5

            Dear @xvalerax
            the page title in the browser bar?

            Best!

            Marius

            www.mariusjopen.world

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            I also code custom websites or custom Lay features.
            💿 Email me here: 💿
            info@laytheme.com

            Before you post:
            1. When using a WordPress Cache plugin, disable it or clear your cache.
            2. Update Lay Theme and all Lay Theme Addons
            3. Disable all Plugins
            4. Go to Lay Options → Custom CSS & HTML, click "Turn Off All Custom Code", click "Save Changes"

            This often solves issues you might run into

            When you post:
            1. Post a link to where the problem is
            2. Does the problem happen on Chrome, Firefox, Safari or iPhone or Android?
            3. If the problem is difficult to explain, post screenshots / link to a video to explain it
            Online Users
            R
            ruwie
            W
            wua.frank
            arminunruhA
            arminunruh
            Forgot your key, lost your files, need a previous Lay Theme or Addon version? Go to www.laykeymanager.com
            laytheme.com
            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Recent
            • Tags
            • Popular
            • Users
            • Search