-
AuthorPosts
-
January 10, 2023 at 12:36 pm #1378115
Good morning everyone,
I have installed the latest version of Enfold on my site, I would like to ask for your help in modifying a text string that is present before the author’s name in blog articles.
In Italian it is translated as “da”, I think in the English version it is “from”, but in Italian it is not understood, it should be written differently (like: “di”, “scritto da”, “a cura di”).
How can I independently edit this string?
Is it also possible to display it immediately below the title of the article?Thank you so much!
January 10, 2023 at 1:57 pm #1378138In English, too, we would differentiate origin in the sentence
I borrowed the book “Hamlet” by Shakespeare from John.
So if you have f.e. portfolios that present books – and the author should now be named in the overviews – and not the creator of the article, then I’m not sure if this can be contextually differentiated.
“Amleto” è di Shakespeare
“Amleto” Ho preso in prestito il libro da JohnJanuary 10, 2023 at 6:10 pm #1378165Yes I understand, I hope there is anyway a way to intervene in the code to fix it directly where it is needed, without having to change translations or anything else.
I await kind help from the Enfold community.January 10, 2023 at 8:55 pm #1378174Hi,
Thanks for your question, we could use javascript to change the “DA” to “DI” and move the line to under the title for Italian language blog posts,
but we will need a link to a sample post to evaluate, please link to a post on your site.
Also do you want the date and the author moved under the title, or just the author?
I assume that you also want this moved in your other language too?Best regards,
MikeJanuary 10, 2023 at 9:06 pm #1378175Hi Mike!
Thank you for your reply, I would only like to have the author at the top of the page (below the title of the article).
The correction with “di” is fine, much better with “A cura di”.
Here an EXAMPLE of my articles.
January 11, 2023 at 2:54 pm #1378267Hi,
Thanks for the link to your site the following function will move the author link on single posts up to under the title next to the category link and for Italian language posts change the “Da” to “A cura di”, it will also change this for your masonry grid on your /blog/ page.
Add this code to the end of your child theme functions.php file in Appearance ▸ Editor:function move_author_and_replace_da() { ?> <script> window.addEventListener('DOMContentLoaded', function() { var moveAuthor = document.querySelector('#top.single-post .post-meta-infos .blog-author.minor-meta'); var appendtoDiv = document.querySelector('#top.single-post .post-entry .blog-categories.minor-meta'); var authorBackslash = document.querySelector('#top.single-post .post-meta-infos .text-sep'); if (!!moveAuthor) { var clone = moveAuthor.cloneNode(true); appendtoDiv.appendChild(moveAuthor).setAttribute('style','margin-left:10px'); authorBackslash.setAttribute('style','display:none'); } }); (function($){ $('html[lang="it-IT"] #top.single-post .post-meta-infos .blog-author.minor-meta').contents().filter(function() { return this.nodeType == 3 }).each(function(){ this.textContent = this.textContent.replace('da ','A cura di '); }); $('html[lang="it-IT"] .av-masonry-author.meta-color.author').text(function(index, text) { return text.replace('da ', 'A cura di '); }); })(jQuery); </script> <?php } add_action('wp_footer', 'move_author_and_replace_da');
After applying, please clear your browser cache and check.
Please see the screenshot in the Private Content area for the expected results.Best regards,
MikeJanuary 11, 2023 at 3:22 pm #1378272Good morning Mike!
Thank you very much, the code works great!One question, is it possible to add a divider character (like ‘/’ ) between the category and “a cura di” under the article title?
Kind of like it was originally at the bottom of the article, where there was a slash symbol between the date and the author’s name.
Thank you for your time
January 11, 2023 at 7:49 pm #1378309January 11, 2023 at 9:10 pm #1378318Done, the coast is clear, you may proceed!
One last thing, I saw that when the mouse cursor hovers over the author’s name in the new location, the colour of the link no longer changes (which it does now that it is back at the bottom of the article).
Is there a possibility of retaining this function or not?
It is not essential, you do not need to spend too much time on this.Thanks!
January 12, 2023 at 2:41 pm #1378401Hi,
Thanks for the feedback, since the author link is now in the categories span the hover color gray was the new color, so add this css to make the categories and author hover color blue like it was when it was below:.html_modern-blog #top.single-post div .main_color .blog-categories a:hover { color: #88bbc8; }
If you don’t want the categories to be blue on hover only the author try this css:
.html_modern-blog #top.single-post div .main_color .blog-categories .author a:hover { color: #88bbc8; }
This is the new script to move the author link and the backslash:
function move_author_and_replace_da() { ?> <script> window.addEventListener('DOMContentLoaded', function() { var moveAuthor = document.querySelector('#top.single-post .post-meta-infos .blog-author.minor-meta'); var appendtoDiv = document.querySelector('#top.single-post .post-entry .blog-categories.minor-meta'); var authorBackslash = document.querySelector('#top.single-post .post-meta-infos .text-sep'); if (!!moveAuthor) { appendtoDiv.appendChild(authorBackslash); appendtoDiv.appendChild(moveAuthor); } }); var changeAuthorNode = document.querySelector('html[lang="it-IT"] #top.single-post .post-meta-infos .blog-author.minor-meta'); if (!!changeAuthorNode) { changeAuthorNode.childNodes[0].replaceWith('A cura di '); } var changeMasonryAuthor = document.querySelector('html[lang="it-IT"] .av-masonry-author.meta-color.author'); if (!!changeMasonryAuthor) { var search = "da "; var replacement = "A cura di "; document.body.innerHTML = document.body.innerHTML.split(search).join(replacement) } </script> <?php } add_action('wp_footer', 'move_author_and_replace_da');
please clear your browser cache and check.
Best regards,
MikeJanuary 12, 2023 at 2:53 pm #1378406Hi Mike,
thank you very much for your help.
The codes work perfectly and fit what I was looking for.Will they remain in the enfold updates or will I have to keep the backup of the function.php?
Thank you!
January 12, 2023 at 3:07 pm #1378411Hi,
Glad to hear, if you are using a Child Theme and the code is in your child theme functions.php then it will work after each update, if it is in your parent theme functions.php and you don’t want to add a Child Theme try using the WPCode plugin and add the code as a “PHP snippet”.
Let us know when you have this working and we will close this thread.Best regards,
MikeJanuary 12, 2023 at 3:32 pm #1378415Hi Mike,
my theme is the main one.. Not child. Can I possibly install it now by exporting all the settings and reverting it to the child one without causing major disruption to the site?
edit: I installed the child theme by exporting the settings from the main theme, it seems to work correctly.
Thanks again for your support.
- This reply was modified 1 year, 11 months ago by APcar.
January 12, 2023 at 4:03 pm #1378430 -
AuthorPosts
- The topic ‘Change string before author in blog article’ is closed to new replies.