Adding #id to the_permalink() - php

I cant seem to figure out the code for this. im currently in the functions.php of my child theme.
i'm trying to have an image link to the comments section of the post. I already have a button that links to the post itself.
the code looks like
<a href="<?php the_permalink(); #reply-title ?>">
<img src="http://trueidconference.com/wowministriesblogs/wp-content/images/JOINimg.png" alt="Mountain View" style="margin-left:12px;"></a>
when I try it, it just doesn't show up. if I use it shows up, but of course doesn't link to the post, then to the id.
I have tried different variations even using echo to get it to work.
But I just cant seem to figure out how to add #reply-title to whatever the current permalink is.
the reason it is in the functions.php is because i needed to add this link to the bottom of every post.

Try:
<a href="<?php echo get_the_permalink(); ?>#reply-title">

If I understand correct you need this:
<a href="<?php the_permalink(); ?>/#reply-title">
<img src="http://trueidconference.com/wowministriesblogs/wp-content/images/JOINimg.png" alt="Mountain View" style="margin-left:12px;">
</a>

Related

php woocommerce ID Custom Field displaying in URL

Pasted Custom Field code into Woo commerce template to display a Custom Field Link.
Code used is:
<a href="<?php the_field('datasheet',the_ID()); ?>" >Download File</a>
But in the front end it adds the Product ID into the url.
it ends up looking like this:
Download Datasheet
Any ideas?
<a href="<?php the_field('datasheet',the_ID()); ?>" >Download File</a>
<a href="<?php the_field('datasheet',the_ID()); ?>" >Download File</a>
The purpose of the_ID() is to display the post id, meaning it will echo it.
You want get_the_ID() here, which only returns the id, but does not directly output it.

Joomla 3.7.1 - Adding Links and title tags to article intro images

Hi guys wondering how I can manually add a link from Joomla intro article images to their corresponding article and also add a title tag to the link.
Ideally the way I want to do this is to for example wrap an achor tag around the image reference in the blog-item.php file (also want to achieve this for generic articles). And then within the anchor tag capture the related image alt tag and populate the title tag with that value.
Below is where I'm at. It's not currently working, not sure why as it should be pretty straight forward. I'm not a php developer, wondering what i'm missing.
Also already cleared both browser and joomla caches after my changes.
Any help would be appreciated, cheers guys
<a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid)); ?>" title="<?php echo htmlspecialchars($images->image_intro_alt); ?>">
<img
src="<?php echo htmlspecialchars($images->image_intro); ?>"
alt="<?php echo htmlspecialchars($images->image_intro_alt); ?>"/>
</a>
To make your code work, add just before your code.
<?php $images = json_decode($this->item->images); ?>
and your code will start working.
Already tested and it worked.

Anchor tag wont render correctly (WordPress PHP)

I am trying to add data atributes to my anchor tag for a WordPress custom theme.
The code below is what I've so far, the problem is with plain HTML this works fine but once I add the PHP lines then something breaks.
When the actual HTML is rendered it excludes the end of the open anchor tag, and leaves "> out to display on the page.
Not sure what went wrong but maybe someone can take a look at this and might be able to point out what I did wrong, a fix, a better way, or maybe if this is even possible.
<a
class="caption" href="<?php the_permalink()?>"
title="<?php the_title_attribute(); ?>"
data-title="<?php the_title(); ?>"
data-description="<?php the_excerpt(); ?>"
>
<?php the_post_thumbnail(array(301,301)); ?>
</a>
<?php endif; endif; ?>
This is not an answer, just some thoughts/things to try:
Are those PHP functions defined somewhere on the same page, or on a page that is included or required ?
Have you tried replacing those function calls with simple PHP commands, such as <?php echo "the_permalink_goes_here"; ?> etc. -- just to make sure, for example, that the anchor tag's href value changes to
<a href="the_permalink_goes_here" etc>
The excerpt function that you're using for the description is returning not just the excerpt, but also an additional "Read more" link, effectively putting an anchor inside your anchor tag, which is what is breaking it. To the best of my knowledge, there isn't a default WP function for returning an excerpt without this link, so you will need a function to do this. Try searching for 'excerpt without link'

dynamically apply title of html document into the title fields of images

Good day.
I am wondering is there any short script to apply the actual page title into the image title? So if I have this page title in my head section:
<head>
<title>Dogs</title>
</head>
and these images:
<a class="sth" href="#" title="PROBLEM"><img src="img01.jpg" alt="sth"/></a>
<a class="sth" href="#" title="PROBLEM"><img src="img02.jpg" alt="sth"/></a>
<a class="sth" href="#" title="PROBLEM"><img src="img03.jpg" alt="sth"/></a>
I want to dynamically apply the title where it says "PROBLEM" from the page title. What is the easiest way of doing this? Does it need to be in php or can it be in javascript?
I just want "Dogs" to go in the place where "PROBLEM" is at the moment if you know what I mean. So probably "PROBLEM" needs to be replaced by a simple script. The document must remain a html by the way.
var title = document.title;
$('.sth').attr('title',title);
Edit, but I don't really see the point of doing this. The title of the site has little to do with the images, if it's added to all of them, what is the point anyways?
in your head part use
<?php
$title_set = "Dogs";
echo "<title>$title_set</t?>itle>";
?>
Every where where you have images use this
<a class="sth" href="#" title="
<?php
echo $title_set;
?>
"><img src="img01.jpg" alt="sth"/></a>
Please remember to change $title_set for each page, or it will be set for every page.
Why couldn't you do this in PHP?
PHP
$title = "Dogs";
HTML
<a class="sth" href="#" title="<?php echo $title; ?>"><img src="img01.jpg" alt="sth"/></a>
<a class="sth" href="#" title="<?php echo $title; ?>"><img src="img02.jpg" alt="sth"/></a>
<a class="sth" href="#" title="<?php echo $title; ?>"><img src="img03.jpg" alt="sth"/></a>
So set a var in PHP, and echo it where you want it to be shown.
PHP would be best so it renders as it should right from the start of the page load (Also so search engines can crawl it). You can do it via javascript, but this may cause dodgy results with SEO.
If you can, always do stuff like this in PHP (Or whatever server side language you code in), unless you absolutely have no other choice to use javascript.

A href tag is not working

Strange thing happens, I have this code, on my wordpress site:
<a href="www.google.com" target="_self" class="facebook" ><img src="<?php echo get_template_directory_uri(); ?>/images/facebook.png"/></a>
The image is loaded, but is not clickable, I mean nothing happens when I click on it, what's wrong?
The link to my page is: http://toibz.com/ibz. Click on the "facebook" logo in the lower right corner.
add http:// to your link like:
<a href="http://www.google.com"..
Set position:fixed on the a tag instead of floating it.

Categories