top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to add text with alt tags on images in Wordpress?

0 votes
312 views

I building a website on Wordpress. When I add this below code

$(document).ready(function() {  
$('#readerareaimg img').each(function(){
var filename = $img.attr('src')
$img.attr('title', filename.substring((filename.lastIndexOf('/'))+1, filename.lastIndexOf('.')));
$img.attr('alt', filename.substring((filename.lastIndexOf('/'))+1, filename.lastIndexOf('.')));
});  

My website will generate alt and title tags automatically on images based on their file name, but I want to add any word or text before the file name. For example file name is phoneimg.jpg and it will display alt="phoneimg", but I want that alt to become alt="read phoneimg". How can I do this?

posted Jun 5, 2017 by Nemai Jana

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

You can use '+' sign in the where you put value of attribute.

$img.attr('alt', 'required word'+filename.substring((filename.lastIndexOf('/'))+1, filename.lastIndexOf('.'))); 

or

$img.attr('alt',filename.substring((filename.lastIndexOf('/'))+1, filename.lastIndexOf('.'))+'required word');
answer Jun 21, 2017 by Debaprasad Maity
Similar Questions
0 votes

I have Wordpress site and I have incorporated Disqus into my posts but I am not sure how to add them to my pages. Any help will appreciated?

0 votes

I need to add a variable inside an array of an embedding gravity forms to populate 2 hidden fields: email and jobname.

Here is my code:

<?php 

    $email = get_field( "email_application" );
    $jobtitle = get_the_title();

    gravity_form( 5, false, false, false, array('email'=>'echo "$email";','jobname'=>'print "$jobtitle";'), false); 
?>

I know that echo, print or just the variable doesn't work as it show like this in my code:

<input name="input_6" id="input_5_6" type="hidden" value="print $jobtitle" class="gform_hidden" aria-invalid="false">

and

<input name="input_5" id="input_5_5" type="hidden" value="echo "$email";" class="gform_hidden" aria-invalid="false">

Instead I should get:

<input name="input_6" id="input_5_6" type="hidden" value="My job title" class="gform_hidden" aria-invalid="false">

and

<input name="input_5" id="input_5_5" type="hidden" value="myaddress@email.com" class="gform_hidden" aria-invalid="false">

Can someone could point me in the right direction.

Thank you.

0 votes

I am developing a wordpress portal. I am sending html content(youtube iframe) with ajax from frontend pages. But while I am inserting that post wp_insert_post removes iframe codes in it. There is no problem with ajax or somewhere else. I guess there is somekind of filter. How can I disable that and insert iframe code?

Code before inserting -> $_POST["content"]

<div class="line nVideo" style="text-align: center;" ><iframe id="player" type="text/html" width="650px" height="380px" src="http://www.youtube.com/embed/mY8BZsIgg74?showinfo=1&amp;enablejsapi=1&amp;color=white&amp;origin=http://432designstudio.com" frameborder="0" allowfullscreen=""></iframe></div><div id="empty-line" class="nText " ><div>gasdgdsag</div>

And after insertation i call content again -> get_post_field('post_content', $postID)

<div class="line nVideo" style="text-align: center"></div><div id="empty-line" class="nText "><div>gasdgdsag</div>
0 votes

I am making a custom plugin for wordpress and i need to create a page in the admin menu. I already have a file called menu_list.php with the following code:

function jps_mail_list_page_entry() {
add_menu_page(
    __('JPS Mailing List'),
    'JPS Mailing List',
    'manage_options',
    'jpsNews_mailinglist',
    'jpsNews_mailing_list',
    'dashicons-email'
);
}
add_action('admin_menu', 'jps_mail_list_page_entry');

function jpsNews_mailing_list() {
    echo 'hello';
}

Now, in the plugin page i have this:

function jpsNews_activate_plugin() {
    include_once(plugin_dir_path(__FILE__).'pages/mailing-list.php');
}
register_activation_hook(__FILE__,'jpsNews_activate_plugin');

Its not working. How can i do it?

+1 vote

I want my permalink to be accessable via more than one slug.

For example:
example-page.com/contact/1234 or example-page.com/contact-1234

...