Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Undefined variable error. WordPress

  • SOLVED

I am using the following for my title tags:


function jp_title_tags() {

if (function_exists('is_tag') && is_tag()) {
single_tag_title("Tag Archive for ""); echo'" - ';
} elseif ( is_archive() ) {
wp_title('');
echo ' Archive - ';
} elseif ( is_category() ) {
wp_title('');
echo ' Category - ';
} elseif (is_search()) {
echo 'Search for "'.wp_specialchars($s).'" - ';
} elseif ( is_front_page() ) {
wp_title(' - ');
} elseif (!(is_404()) && (is_single()) || (is_page())) {
wp_title(''); echo ' - ';
} elseif (is_404()) {
echo 'Page Not Found - ';
};
if (is_home()) { bloginfo('name');
}
else { bloginfo('name'); } ?><?php if ($paged>1) { echo ' - page '. $paged; }
}

if( is_single() ) {
$keywords = get_the_tags();
if( $keywords ) {
foreach($keywords as $keyword) {
echo $keyword->name . ', ';
}
}
}


But I am getting this error message from it:

Notice: Undefined variable: paged in ....._include/title_meta.php on line 25<br />

Answers (5)

2014-02-14

Navjot Singh answers:

You need to initialise $paged variable first.

Add this line

$paged = $wp_query->get( 'paged' );

after

function jp_title_tags() {

2014-02-14
2014-02-14

webGP answers:

Hello!

Pleas add this line of code:


$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;


after this line:


function jp_title_tags() {


julesphoto comments:

Hello, your solution was the first and it seems to have solved the problem. Thanks to everyone for their replies.

2014-02-14

Firoja_Imtosupport answers:

Hi,

add the following line $paged = ''; after function jp_title_tags() {

Note:
If your site is live, then you should have NOTICE messages disabled.

2014-02-14

Hariprasad Vijayan answers:

Hello,

Change following code

if ($paged>1) { echo ' - page '. $paged; }

with

if (!empty($paged) && $paged>1) { echo ' - page '. $paged; }