Show a custom URL in the header on a WordPress post - php

I am trying to achieve a customized url that shows in url header. Different for every WordPress post.
For example, I have posts in WordPress about different countries what I want is that when I click on a country the single post page which normally shows up like this in the browser url field:
www.example.com/2017/11/china
Should show up like this, only in header like.
china.example.com or
russia.example.com
I don't know if I can achieve this using WordPress or Do I have to play around with .htaccess file.
There are more than 200 posts and I am trying to find a way to do it using an automated script or WordPress code.
I want this link to be associated with the actual post on the WordPress site. Please let me know if it's achievable or if there is already a post on stack overflow that solves this. I couldn't find one. Thank you.

china.example.com is a subdomain, example.com/.../china is a folder. They are actually two different things. To achieve this effect though, you would need to set up a multi-site wordpress installation, and treat china.example.com as one website and russia.example.com as another

Related

How can I rename the WordPress AJAX URL?

I'm currently looking for a way to change / hide the default WordPress admin-ajax.php URL. I want to do this to remove the admin from it to prevent misunderstandings by my customers when I use the AJAX URL to read for example a file from my server. In this case, the URL has the admin prefix which is a bit confusing.
So in result the AJAX URl should looks like this: ajax.php
I've searched a bit but I can't find any helpful information. Because of this I can't show you any related code. But when I got it, I'll update my question to help other people.
Alternatively and perhaps more effectively you could leverage WP API and create a custom endpoint to process your data so that there isn't url confusion.

Whats the best way to change the content urls in the WordPress Rest API results?

Say I have api.wordpresssite.com where I will be entering data, uploading images and so on. Then saw that I want to consume the WordPress API on another site like mysite.com.
WordPress will then assume that every link in content will be api.wordpresssite.com It will also embed images with the same URL because the links and media are absolute.
Am I supposed to process the content on mysite.com looking for links but ignoring media or is there a plugin or function that I can add to my theme to do this?
I have tried changing the base URL and while it works for links, it breaks media uploads.
There are multiple endpoints so I am thinking that even if there was a function to add, it would be too far down the line of execution to do anything.
For Example, there is the WP API, as well as JetPack, and Yoast that I am using.
There are tonnes of articles on "How to use WordPress in Laravel" but not a single article has talked about how to "normalize" the content for the site that is consuming it.
The API feels like it's only true out of the box use is to be used with some kind Javascript based front end.
What I would like is a headless WordPress API with relative URLs for content links.
I was looking for the same answer and solved it this way:
What you would need to do is set the site URL to www.remote-domain.com.
You can do this by going to WP Admin > Settings > General
Screenshot
Then on your functions.php file or somewhere you can add a filter (plugin etc.) add this filter in.
add_filter( 'rest_url', 'fix_rest_url');
function fix_rest_url( $url ) {
return $url;
}
Got the answer from: https://core.trac.wordpress.org/ticket/49146
My suspicion that no one really uses the WordPress API seems to be confirmed. Mainly on an external site.
I had to create some render methods that looked for HREF links and remap them on the content, and menus.
It still seems silly and not very polished.

Multiple pages for custom_post_type posts

I have a custom_post_type that creates the posts for campaign_posts, they are displayed singularly on the front-end of my site with the page template single-campaign_posts.php.
Now, what I am trying to achieve is;
single-campaign_posts.php displays the post (already taken care of)
A second page that will display a frontend editor of the post (contents of this page is already taken care of
A third page that will display analytics for the post (again, the contents of this page has been taken care if)
So when a post is viewed they can click a link within single-campaign_posts.php to display either the analytics page or edit page. The pages that are linked to must be;
able to recognize that the contents of that page relate to the post
the URL slug is for example if the post was /campaigns/dummy-post would be /campaigns/dummy-post/analytics for the analytics page and /campaigns/dummy-post/edit-campaign for the edit page.
I have tried using nav tabs to do this and it works, however, I would rather have the contents on separate pages.
I hope this enough information to obtain my goals in this. I cannot see much point in adding details of the functions.phpor single-campaign_posts.php but if they are required then please let me know.
I hate seeing posts like this, but I have come up empty on searches for a solution. In its very basic form, I need three pages that all relate to the single post.
Thank you for your time and if you need more information please let me know.
I have found the solution to this now.
The solution was to use Rewrite API/add rewrite endpoint as seen Rewrite API/add rewrite endpoint
An example is posted in this question - Create Post tabs in single-{content-type}.php with Custom Field values

Integrating WordPress with a website, generically

So, I've read The Loop and I got the hang of it. (I created a page that lists the 3 most recent posts, a page that shows a page (as opposed to a post), and so on.)
However, it seems silly that, in order to integrate a WordPress blog into an existing site, I'd have to replicate all the different kinds of pages (lists of posts, the posts themselves, pages, etc.)
Is there a generic way of doing this?
The full idea is something like this.
The blog itself (with its ugly default template) is installed at http://blog.example.com.
I want to integrate the blog into an existing site, at the URL http://example.com/blog.
I'm doing a mod_rewrite that forwards the entire query string, e.g. http://blog.example.com/?p=7 gets rewritten to http://example.com/blog?p=7.
Now, in my PHP code at http://example.com/blog, I want to do something like this:
query_posts($_GET);
// display results
wp_reset_query();
That's where I'm stuck. Basically, I want to display exactly what's in the "content" area of a default WordPress template, on my site, according to whatever the query string dictates. Almost as if I were just using an iframe. I would rather not have to parse the query string to figure out whether I have to loop through this or that or turn off the $more global or not, etc.
What am I missing?
Instead, should I be installing the blog at http://example.com/blog and creating a template that mimics the website? This seemed complicated so I didn't go this route, but maybe someone should change my mind.
Appreciate any help, including advice for alternative designs.
Have you considered outputting the blog into a full rss/ outputting the blog as json and then pulling it in that way?

Prestashop - custom template link

I'm starting with "PrestaShop" and I just can't figure out, how to put a link in template to custom page I created in CMS module... I thought, there might be some easy way, as there is in WordPress, like "get_permalink(ID)", but there's nothing like this and I can't find anything about this anywhere and it just drives me mad.
So, here's the deal, I've got a custom template, and there are some top links, like "About Us". I've created this page in CMS and it has ID "6".
How do I make this bloody "PrestaShop" to generate a link to this page in my template file?
About
I think you're looking for SMARTY template tags and custom variables defined for Prestashop specifically. The one the you probably need is {$base_dir} which will be translated to http://www.yoursite.com/ obviously with appropriate protocol (non-secure HTTP or secured HTTPS).
After that, you only need to include page URL, which you can get from Admin->Tools->CMS section.
If I find any specific tags that you can use to call the content, I will update my post here.
Your Text
the "WHAT goes here" is just the url you want your link drives the client to when clicking on that link.
You need to understand a little minimum of HTML for this I guess. Check html tag a meaning .
Prestashop has a fairly good and extensive documentation. Two and half seconds googling drives me here, just like answering your question it looks like.

Categories