how can i set all links ( internals , externals , photos ) on all posts (WordPress) in new tab (target="_blank") ?
i don`t want to open menu links and other themes links in new tab ! only links on post.
functions codes or another code
if your theme adds class to body, you should have post class "single-post"
then in JS - add:
$(".single-post a").attr("target","_blank");
if your theme doesn't add class to body, add this:
<body <?php body_class($class); ?>>
Related
I am new to wordpress. I have started creating custom theme. I am getting my content via following method:
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
//
the_content()
//
} // end while
} // end if
?>
I added lot of images on my website. These images are automatically sizing from wordpress. I want to add hyperlink (link of same image) to all images in a post. But I don't want to do this manually one by one.
Following is example of what I want to achieve:
<img src="sample.img" />
//to convert
<a href="sample.img" class="mycustomclass">
// Image link:
<img src="sample.img">
</a>
Follow These steps to link an image in Wordpress WYSIWYG editor.
https://en.support.wordpress.com/links/image-links/
I want a search button at the right side of the primary menu which display a searchbox under primary menu once it is clicked.I am a newbie in wordpress and only know html and php basic.Can anyone please help me out?
To add the Custom Items into your menu , Then you should use the filter hook wp_nav_menu_items.
Please see the below Code and paste it into the current active theme functions.php file :
add_filter('wp_nav_menu_items','add_search_box_into_menu', 10, 2);
function add_search_box_into_menu( $nav, $args ) {
if( $args->theme_location == 'primary' )
$nav .= '<li class="custom-header-search"><form action="'.home_url( "/" ).' id="searchform" method="get"><input type="text" name="s" id="s" placeholder="Search"></form></li>';
return $nav;
}
For more help : See here
You'll need to add not just a link, but the search form.
To do so, you need to customize your theme.
Important: if you use a theme you didn't create, then first create a child theme and modify it (it will ensure you that your changes are still applied ethen if the theme recieve updated).
Then in the HTML/PHP code where you menu is, you can use the get_search_form() method to display the search form in place.
If you want to customize the search form, juste create a searchform.php file in your theme folder and customize it.
More informations here : https://codex.wordpress.org/Styling_Theme_Forms
How to hide items in the square? This is in a custom plugin.
Click here
You can create plugin for this (i.e. Remove attachment filed). Below are the steps to create plugin for your requirement:
1) Create one folder inside wp-content/plugin (i.e. Remove attachment filed)
2) Inside newly created folder create one file (i.e remove_attachment_details.php) with below code.
3) Activate the plugin from Admin >> Plugins
<?php
/*
Plugin Name: Remove attachment filed
*/
add_action('admin_head-post.php', 'hide_media_stuff_wpse_120894' );
add_action('admin_head-post-new.php', 'hide_media_stuff_wpse_120894' );
function hide_media_stuff_wpse_120894(){
?>
<style type="text/css">
.attachment-details [data-setting="title"],
.attachment-details [data-setting="caption"],
.attachment-details [data-setting="alt"],
.attachment-details [data-setting="description"],
div.attachment-display-settings
{
display:none
}
</style>
<?php
}
?>
I want to modify the Travelify Wordpress Theme.
I want to put some options like Home|Contact Us|Search on the header.
I want to put an image on the footer.
Question
How can I achieve these changes to the theme?
If you want to make a navigation menu on header, you must setting your menu first.
Setting your navigation menu on appearance>menu
You can setting your footer on appearance>widgets
Try SiteOrigin Widgets bundle plugin for more Widgets on your wordpress.
And for a custom CSS, I use SiteOrigin CSS.
First go to 'wordpress/wp-content/theme' folder and generate an directory with similar name as your theme name.Let say theme name is 'travelify' then use child theme name as 'travelify-child'.
Now go to 'travelify-child' folder and add two files i.e.(style.css and functions.php)
Now open style.css from parent theme i.e.'travelify'
copy all css code and paste into new style.css in 'travelify-child' folder.
don't forget to change theme name,description,text domain.
Add 'Template: travelify' in to style.css.....you can add it after anyline in header like after 'Author URI'.
Now save this style.css and open functions.php in 'travelify-child' foder
and paste below code into functions.php
<?php
add_action( 'init' , 'remove_copyright' , 15 );
function remove_copyright() {
remove_action( 'travelify_footer', 'travelify_footer_info', 30 );
}
add_action( 'travelify_footer' , 'new_footer_info' , 30 );
function new_footer_info() {
$output = '<div class="copyright">Copyright © 2016 Your website name.Powered by Wordpress.
Wordpress</div>';
echo $output;
}
?>
This is what I need to do:
To target only the main shop page with CSS (a specific custom class I created as mentioned below).
This is what I've done and tried so far:
I have an override template of archive-product.php in my child theme.
In this override template I've added a div with a custom class custom-shop-class just before the product loop start, because I want to target the looped products specifically.
I tried targeting with class page-id-4 because if I hover over the "shop" page in wp-admin, it gave me http://.../post.php?post=4&action=edit
The problem I'm having is as follows:
From what I've discovered is that the same archive-product.php template is being used in the other various shop pages and not only in the main "shop" page (correct me if I'm wrong), so when I target my custom-shop-class with CSS, it affects all the other shop pages using the same template file, and it must not.
There is no unique identifier or class specifically for the shop page, something like the page-id-?? class in the body tag (as in the usual WP pages).
Any suggestions on the best method/solution?
Set a conditional statement to check for the primary shop page, then echo the div in question if that statement evaluates to true.
WooCommerce Conditional Tag for main shop page:
is_shop()
Example
if (is_shop()) {
echo "<div class='custom-shop-class'></div>";
} else {
echo "<div class='custom-product-category-class'></div>";
}
Alternatively:
<?php if (is_shop()):?>
<div class="custom-shop-class"></div>
<?php else: ?>
<div class="custom-product-category-class"></div>
<?php endif;?>
Conditional Tags | WooThemes Documentation
Using the filter body_class with the is_shop conditional you can target the main WooCommerce shop page.
add_filter( 'body_class', 'woo_shop_class' );
// Add WooCommerce Shop Page CSS Class
function woo_shop_class( $classes ) {
if ( is_shop() ) // Set conditional
$classes[] = 'woo-shop'; // Add Class
return $classes;
}
The code goes in your themes functions.php file.
To build on the answer provided here, how might I go further and add a unique identifier to the shop page based on the active WPML language? (I'm basically trying to reduce a font size on the German version of the shop page only - it's proving surprisingly difficult to do)